Rename files before FTP Download

Discuss RoboTask here
Post Reply
des1
Posts: 6
Joined: Sun Feb 13, 2005 10:34 am
Location: United States
Contact:

Rename files before FTP Download

Post by des1 »

Hello...
I am trying to rename a file before it is downloaded, but I am having a brain freeze on getting this to work.  I can easily connect to the source, download all the files and log off, but I need to rename each file before it is downloaded to FileName.DateTime to eliminate overwriting an existing file in the destination folder
i.e. Files on the source are "a.txt", "b.txt", etc., I need them to be renamed to "a.txt.DateTime", "b.txt.DateTime", etc., then download them. 
Thanks,
Deryk
Oleg
Site Admin
Posts: 3014
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Rename files before FTP Download

Post by Oleg »

In order to prevent overwriting of files you can download it into buffer folder instead of destination folder. And next you can rename it and move into destination folder.

For example: you need to download a.txt, b.txt, c.txt (and others) from FTP, but you must save old versions of these files. Downloaded files stored in folder named "\destination".

See approximate algorithm below:

FTP file loop and assign each file name to FileName variable
   download {FileName} file into "\BufferFolder"
   rename \BufferFolder\{FileName} to \BufferFolder\{FileName}.{ValidFileName({DateTime})}
   move \BufferFolder\{FileName}.{ValidFileName({DateTime})} to "\destination" folder
end FTP file loop
Oleg
Site Admin
Posts: 3014
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Rename files before FTP Download

Post by Oleg »

See example task below.
Save text of task into any file and use menu "Task | Import" to import example into RoboTask

;**********************
;* RoboTask Task file *
;* Do not edit!       *
;**********************

[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|1664541561
ContinueOnError=INTEGER|0
ExternalName=STRING|"Task216"
Hide=INTEGER|0
ID=INTEGER|2016113661
Name=STRING|"Download and rename"
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3

[Actions]
Action1=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER
Action7=FOLDER
Action8=FOLDER
Action9=FOLDER

[Actions\Action1]
ActionID=STRING|"A_FTP_LOGON"
Enabled=INTEGER|-1
Name=STRING|"FTP Log On"
Params=FOLDER

[Actions\Action1\Params]
anonymous=STRING|"1"
host=STRING|"localhost"
passive=STRING|"0"
password=STRING|"4231738316406194034628830408604112640602242 423831113485"
port=STRING|"21"
username=STRING|"anonymous"

[Actions\Action2]
ActionID=STRING|"A_FTP_TRANSFERTYPE"
Enabled=INTEGER|-1
Name=STRING|"FTP Transfer Type"
Params=FOLDER

[Actions\Action2\Params]
binary=STRING|"1"

[Actions\Action3]
ActionID=STRING|"A_FTP_FILELOOP"
Enabled=INTEGER|-1
Name=STRING|"FTP File Loop"
Params=FOLDER

[Actions\Action3\Params]
filenameonly=STRING|"1"
folder=STRING|"*.html"
sizesave=STRING|"0"
subfolders=STRING|"0"
timesave=STRING|"0"
varname=STRING|"FTPFILE"

[Actions\Action4]
ActionID=STRING|"A_FTP_DOWNLOAD"
Enabled=INTEGER|-1
Name=STRING|"FTP Download"
Params=FOLDER

[Actions\Action4\Params]
file=STRING|"{ftpfile}"
folder=STRING|"d:\temp"

[Actions\Action5]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""NEWFILENAME"" with value ""{FTPFile}.{ValidFileName({DateTime})}"""
Params=FOLDER

[Actions\Action5\Params]
expand=STRING|"1"
varname=STRING|"NEWFILENAME"
varvalue=STRING|"{FTPFile}.{ValidFileName({DateTime})}"

[Actions\Action6]
ActionID=STRING|"A_FOLDER_CHANGE"
Enabled=INTEGER|-1
Name=STRING|"Change Folder (d:\temp)"
Params=FOLDER

[Actions\Action6\Params]
folder=STRING|"d:\temp"

[Actions\Action7]
ActionID=STRING|"A_FILE_RENAME"
Enabled=INTEGER|-1
Name=STRING|"Rename File"
Params=FOLDER

[Actions\Action7\Params]
count=STRING|"1"
file0=STRING|"{FTPFile}"
mask=STRING|"{newfilename}"
subdirs=STRING|"0"

[Actions\Action8]
ActionID=STRING|"A_FILE_COPY"
Enabled=INTEGER|-1
Name=STRING|"Copy/Move File"
Params=FOLDER

[Actions\Action8\Params]
destdir=STRING|"d:\destination"
f_count=STRING|"1"
file0=STRING|"{NewFileName}"
ifexists=STRING|"0"
move=STRING|"1"
subdir=STRING|"0"

[Actions\Action9]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"
des1
Posts: 6
Joined: Sun Feb 13, 2005 10:34 am
Location: United States
Contact:

Rename files before FTP Download

Post by des1 »

Oleg, that makes sense.  Thank you for the quick response and I will try it out.
Post Reply