We have root access to an FTP site and, using Filezilla, we can search the site and delete files meeting a date criteria.
We would like to automate this process in Robotask; but I haven't been able to find the commands that would allow me to do so. I've searched this forum and still haven't found anything that applies to what we want to do.
Specifically we would like to search for files that are two weeks older than today's date and delete them. We would like to do this once a day.
I have an idea on how we would create the variables for the search {Year}{Month}{IncDays(-14)}, but I don't know what command to apply them to. I've tried using the Search For Files command, but it doesn't seem to work with FTP.
Any help would be appreciated.
Search and Delete Files on an FTP Site
Re: Search and Delete Files on an FTP Site
You should use FTP File loop (or SSL FTP File loop)
Look at the example below. I've just tested this on our server.
SSL FTP actions support plain FTP too
You can get File name, file size and file time in the loop.
Next, you can compare these values and check your criteria.
Use variable {DateIncDays(-14)} to calculate necessary date.
{YearIncDays(-14)}{MonthIncDays(-14)}{IncDays(-14)}
Look at the example below. I've just tested this on our server.
SSL FTP actions support plain FTP too
Code: Select all
;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|264082567
Comment=STRINGLIST
ContinueOnError=INTEGER|0
ExternalName=STRING|"Task105"
Hide=INTEGER|0
ID=INTEGER|2083680061
LogOnAsUser=INTEGER|1
Name=STRING|"Find FTP File older 14 days"
OnErrorTaskID=INTEGER|0
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
WriteGeneralLog=INTEGER|0
[Actions]
Action1=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER
Action7=FOLDER
Action8=FOLDER
Action9=FOLDER
[Actions\Action1]
ActionID=STRING|"A_SSLFTP_LOGON"
Enabled=INTEGER|-1
Name=STRING|"SSL FTP Log On"
Params=FOLDER
[Actions\Action1\Params]
anonymous=STRING|"1"
host=STRING|"ftp.site.com"
passive=STRING|"1"
password=STRING|"42310383162884337286400984055142142"
port=STRING|"21"
proxypassword=STRING|"2488925200257142494526994"
proxytype=STRING|"3"
tlsmode=STRING|"0"
useproxy=STRING|"0"
username=STRING|"anonymous"
usessl2=STRING|"0"
usessl3=STRING|"0"
usestls=STRING|"1"
[Actions\Action2]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create local variable ""C_FILE"" with value """""
Params=FOLDER
[Actions\Action2\Params]
expand=STRING|"0"
varkind=STRING|"1"
varname=STRING|"C_FILE"
[Actions\Action3]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create local variable ""C_DATE"" with value """""
Params=FOLDER
[Actions\Action3\Params]
expand=STRING|"0"
varkind=STRING|"1"
varname=STRING|"C_DATE"
[Actions\Action4]
ActionID=STRING|"A_SSLFTP_FILELOOP"
Enabled=INTEGER|-1
Name=STRING|"SSL FTP File Loop"
Params=FOLDER
[Actions\Action4\Params]
filenameonly=STRING|"0"
folder=STRING|"/files/*.*"
kind=STRING|"0"
sizesave=STRING|"0"
subfolders=STRING|"0"
timesave=STRING|"1"
varname=STRING|"C_FILE"
vartime=STRING|"C_DATE"
[Actions\Action5]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER
[Actions\Action5\Params]
message=STRING|"{C_file}; {c_date}"
type=STRING|"3"
[Actions\Action6]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then"
Params=FOLDER
[Actions\Action6\Params]
case=STRING|"0"
operator=STRING|"5"
type=STRING|"2"
value1=STRING|"{c_date}"
value2=STRING|"{DateIncDays(-14)}"
[Actions\Action7]
ActionID=STRING|"A_ROBOTASK_ALERT"
Enabled=INTEGER|-1
Name=STRING|"Desktop Alert"
Params=FOLDER
[Actions\Action7\Params]
defh=STRING|"1"
defw=STRING|"1"
duration=STRING|"5"
height=STRING|"76"
icon=STRING|"1"
kind=STRING|"0"
message=STRING|"file {c_file} ({c_date}) older than 14 days"
position=STRING|"3"
title=STRING|"Old file"
width=STRING|"330"
[Actions\Action8]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"
[Actions\Action9]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"
Next, you can compare these values and check your criteria.
Use variable {DateIncDays(-14)} to calculate necessary date.
If you want to compose date expression manually you should use something like this:...the variables for the search {Year}{Month}{IncDays(-14)}, but I don't know...
{YearIncDays(-14)}{MonthIncDays(-14)}{IncDays(-14)}
Oleg Yershov
Re: Search and Delete Files on an FTP Site
Oleg,
Thanks for your reply and the code. I did have a couple of questions...
Creating the local variable for the file name, what do I need to put in as that variable so that I can use the existing file name?
Also, in the If/Then statement you have a desktop alert. Is that where I put the delete statement? And do I put the c_file variable in as the remote file to be deleted?
Thanks for your reply and the code. I did have a couple of questions...
Creating the local variable for the file name, what do I need to put in as that variable so that I can use the existing file name?
Also, in the If/Then statement you have a desktop alert. Is that where I put the delete statement? And do I put the c_file variable in as the remote file to be deleted?
Re: Search and Delete Files on an FTP Site
Variables C_File and C_Date in the example are being assigned in each iteration of the loop (SSL FTP file loop, step #4).
But pay attention that C_file contains the file name only.
You do the loop by /files/*.* . Therefore you should remove /files/{cfile}
Another way:
You can put the action SSL FTP change folder (to /Files folder) before the loop.
Do the loop by *.*
And use {c_file} as parameter of SSL FTP Delete file action.
see new example below. I recommend you to test it on local or test server, because files removing is potentially dangerous operation
But pay attention that C_file contains the file name only.
You do the loop by /files/*.* . Therefore you should remove /files/{cfile}
Another way:
You can put the action SSL FTP change folder (to /Files folder) before the loop.
Do the loop by *.*
And use {c_file} as parameter of SSL FTP Delete file action.
see new example below. I recommend you to test it on local or test server, because files removing is potentially dangerous operation
Code: Select all
;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|2099193306
Comment=STRINGLIST
ContinueOnError=INTEGER|0
ExternalName=STRING|"Task321"
Hide=INTEGER|0
ID=INTEGER|732090254
LogOnAsUser=INTEGER|1
Name=STRING|"Find FTP File older 14 days"
OnErrorTaskID=INTEGER|0
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
WriteGeneralLog=INTEGER|0
[Actions]
Action1=FOLDER
Action10=FOLDER
Action11=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER
Action7=FOLDER
Action8=FOLDER
Action9=FOLDER
[Actions\Action1]
ActionID=STRING|"A_SSLFTP_LOGON"
Enabled=INTEGER|-1
Name=STRING|"SSL FTP Log On"
Params=FOLDER
[Actions\Action1\Params]
anonymous=STRING|"1"
host=STRING|"localhost"
passive=STRING|"1"
password=STRING|"42310383162884337286400984055142142"
port=STRING|"21"
proxypassword=STRING|"2488925451249452673325197"
proxytype=STRING|"3"
tlsmode=STRING|"0"
useproxy=STRING|"0"
username=STRING|"anonymous"
usessl2=STRING|"0"
usessl3=STRING|"0"
usestls=STRING|"1"
[Actions\Action10]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"
[Actions\Action11]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"
[Actions\Action2]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create local variable ""C_FILE"" with value """""
Params=FOLDER
[Actions\Action2\Params]
expand=STRING|"0"
varkind=STRING|"1"
varname=STRING|"C_FILE"
[Actions\Action3]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create local variable ""C_DATE"" with value """""
Params=FOLDER
[Actions\Action3\Params]
expand=STRING|"0"
varkind=STRING|"1"
varname=STRING|"C_DATE"
[Actions\Action4]
ActionID=STRING|"A_SSLFTP_CHANGEFOLDER"
Enabled=INTEGER|-1
Name=STRING|"SSL FTP Change Folder"
Params=FOLDER
[Actions\Action4\Params]
folder=STRING|"/files"
[Actions\Action5]
ActionID=STRING|"A_SSLFTP_FILELOOP"
Enabled=INTEGER|-1
Name=STRING|"SSL FTP File Loop"
Params=FOLDER
[Actions\Action5\Params]
filenameonly=STRING|"0"
folder=STRING|"*.*"
kind=STRING|"0"
sizesave=STRING|"0"
subfolders=STRING|"0"
timesave=STRING|"1"
varname=STRING|"C_FILE"
vartime=STRING|"C_DATE"
[Actions\Action6]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER
[Actions\Action6\Params]
message=STRING|"{C_file}; {c_date}"
type=STRING|"3"
[Actions\Action7]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then"
Params=FOLDER
[Actions\Action7\Params]
case=STRING|"0"
operator=STRING|"5"
type=STRING|"2"
value1=STRING|"{c_date}"
value2=STRING|"{DateIncDays(-14)}"
[Actions\Action8]
ActionID=STRING|"A_ROBOTASK_ALERT"
Enabled=INTEGER|-1
Name=STRING|"Desktop Alert"
Params=FOLDER
[Actions\Action8\Params]
defh=STRING|"1"
defw=STRING|"1"
duration=STRING|"5"
height=STRING|"76"
icon=STRING|"1"
kind=STRING|"0"
message=STRING|"Delete file {c_file}"
position=STRING|"3"
title=STRING|"Old file"
width=STRING|"330"
[Actions\Action9]
ActionID=STRING|"A_SSLFTP_DELETEFILE"
Enabled=INTEGER|-1
Name=STRING|"SSL FTP Delete File"
Params=FOLDER
[Actions\Action9\Params]
file=STRING|"{c_file}"
Oleg Yershov