PDA

View Full Version : [TCL] Renaming a file on PRE STOR


Ofloo
05-06-2004, 03:23 PM
i got this under pre

[FTP_Pre-Command_Events]

stor = TCL ..\scripts\ioSfv\ioSfv.tcl sfvstore

i want to rename from filename.incomplete to filename

for some reason this doesn't seem to be working anyone any ideas ??

i think its the pre thing .. cause

--------------------------- ErrorInfo ----------------------------
error renaming "..\site\test\15[.mp3.incomplete" to "..\site\test\15[.mp3": file already exists
while executing
"file rename -- $path\\[lindex $arg end].incomplete $path\\[lindex $arg end]"
(procedure "sfvstore" line 6)
invoked from within
"sfvstore "$args""
invoked from within
"if {[info exists args]} {
if {[string match -nocase sfvcheck [lindex $args 0]]} {

neoxed
05-06-2004, 04:00 PM
Try posting related portions of your code, or are we supposed to read your mind? :p

tuff
05-06-2004, 04:08 PM
"file rename -- $path\[lindex $arg end].incomplete $path\[lindex $arg end]"

im almost sure if you place a \ before a [ in tcl, tcl will interpet the [ as part of the string and NOT as a command

since your using the same command twice there, why not simply

set what [lindex $arg end] ?

Ofloo
05-06-2004, 04:12 PM
as in reading my mind isn't that hard pre stor and file rename ..

well i wana rename a file as i suggested from filename.incomplete to filename


now as in \[ i knwo about this i think the forum removes it .. just found out if u put [php] arround it it strips crap

proc sfvstore {arg} {
global path
set arg [string map {\\ \\\\ \[ \\\[ \] \\\] \{ \\\{ \} \\\} \( \\\( \) \\\)} $arg]
set path [string map {\\ \\\\ \[ \\\[ \] \\\] \{ \\\{ \} \\\} \( \\\( \) \\\)} $path]
if {[file exists $path\\[lindex $arg end].incomplete]} {
file rename -- $path\\[lindex $arg end].incomplete $path\\[lindex $arg end]
iputs -nobuffer "$path\\[lindex $arg end].incomplete $path\\[lindex $arg end]"
}
}

Ofloo
05-06-2004, 04:25 PM
226 ABOR command successful.
User Aborted
PASV
227 Entering Passive Mode (192,168,0,100,7,149)
REST 1310720
350 Restarting at 1310720. Send STORE or RETRIEVE to initiate transfer.
STOR 15.mp3
Renameing ..\site\test\15.mp3.incomplete to ..\site\test\15.mp3
150 Opening BINARY mode data connection for 15.mp3.

i tryed with and without mapping string or regsub if u prefer i prefer string map its faster and does same thing :p

Ofloo
05-06-2004, 04:26 PM
altho it could be post .. let me check that ..

Ofloo
05-06-2004, 04:28 PM
no thats not it it must be something else tho cause the resume is set before stor so what would u suggest i use sinds post isn't triggerd ..

Ofloo
05-06-2004, 04:45 PM
no it is stor just before stor i have to do

iputs -nobuffer REST [file size $path\\[lindex $arg end].incomplete]
then rename it but for some reason tis isn't working ...

neoxed
05-06-2004, 05:13 PM
Originally posted by Ofloo
as in reading my mind isn't that hard pre stor and file rename ..
No, If you read my original statement I was referring to your code not your idea.

Originally posted by Ofloo
i tryed with and without mapping string or regsub if u prefer i prefer string map its faster and does same thing :p
Well if you read the TCL documentation, regsub and string map have very different uses. Regsub is used for regular expression substitutions and string map simply replaces one or several characters in a given string.

In your sample code, you should be using "lrange $arg 1 end" rather then "lindex $arg end". If someone uploaded a file that contained a space, your script would fail.

if {[file exists $path\\[lindex $arg end].incomplete]} {
file rename -- $path\\[lindex $arg end].incomplete $path\\[lindex $arg end]
iputs -nobuffer "$path\\[lindex $arg end].incomplete $path\\[lindex $arg end]"
}

On "pre stor" events, the file doesn't exist yet. So the [file exists ...] is meaningless. Thus why your file is not being renamed. Try using "post stor" if wasn't so lazy at the moment, I would try myself. ;)

Ofloo
05-06-2004, 05:20 PM
file exists has meaning tho i check if file incomplete exists to rename it cause if its not there it will return an error also normal i check for the other file but sinds it is no use cause the pre doesn't work well left it out ..

if u check the error u would know :p cause it cant be renamed it is saying can't rename cause file allready exists witch means it is renameing it

i could check if the target file exists or use -force but sinds the file is openend for writing, .. wouldn't do mutch good .. so .. no point realy i could check if the traget file is there in order to prevent an error but still my problem remains all it would do is not return an error

also pre does exist cause it is triggerd if it would not exist then it wouldn't trigger that it is not pre that i know cause it is executed after the event also i tryed lrange and if u wana use lrange u should also add join other wize it has no effect cause then u get { } on spaces witch is not the idea .. sinds i wana make it work first then worry about the spaces i used lindex .. sinds there are no spaces in my current path.

[join [lrange $arg 2 end]]

other wize it will only add {}

i know about string map and regsub but there is nothing u can change by replacing {} to [] and the code will be executed then just mapped .. also all i need to do is replace ;) so ..

neoxed
05-06-2004, 05:32 PM
I still don't see the point in renaming the file on "pre stor"...it would be much more logical to rename the file on the OnUploadComplete event.

Ofloo
05-06-2004, 06:40 PM
The whole point is when a file is incomplete not when it is complete that crap i got sorted its once u wana resume

look i don't want incomplete files to be renamed to .bad

also u don't need lrange sinds the arguments in ioftpd have "" arround them thats basicly the same as

{argument argument}

if u do lindex 0 on that u will get argument argument as result ..

as i sad basicly it comes down to the same thing this means i am not saying it is !!

one of the mestakes in easySFV he splits it on "

darkone
05-06-2004, 11:36 PM
How about renaming it on [post] stor ;? that would tell you, wheter file create actually succeeded. (only problem you will encounter, that after failed upload - you must take care of file yourself.. io will try to delete file with invalid name, which propably makes any other script go crazy)

Ofloo
05-07-2004, 11:45 AM
hmm ic