Delete files on ftp server older than x days

Started by jpaton, January 13, 2016, 10:03:49 AM

Previous topic - Next topic

jpaton

Does anyone know of a way to login to an ftp server and delete files older than x amount of days?  I know how to do it with regular folders (c:\temp, etc) by using a function but I'm not sure how it would work on an ftp server where I can't specify a drive letter and folder.  Any ideas are greatly appreciated.

td

Check out the WinInet extender's iFtpCmd (MDTM command) and iFtpDelete functions.  Not aware of any working examples but will check around and post if I find something.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

Here is quick and dirty example that does some of what you require.  It gets the modify time of a file and deletes it, if it wasn't modified today:

Code (winbatch) Select
AddExtender("WWINT44I.DLL")

UserId="me"
Pswd="*topsecret*"
SERVER="my.server.com"

tophandle=iBegin(0,"","")

conhandle=iHostConnect(tophandle,SERVER,@FTP, userid,pswd)
If conhandle==0
      Message("ERROR","Unable to connect to host")
      Exit
EndIf

; Get the modify date.
strTime = iFtpCmd(conhandle, 'MDTM', 'test.txt', @ASCII)

; Cleanup result - exactly how depends on server's return info.
strTime = ItemExtract( 1, ItemExtract(2, strTime, ' '), @CR)

nResult = 0
if  strTime < '20160113000000'  ; If it wasn't modified today.
   nResult = iFtpDelete(conhandle, 'test.txt')
endif

Message("File Deleted?", nResult)
iClose(conhandle)
iClose(tophandle)
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

jpaton

Thanks, that is helpful.  I was hoping to find a way to check all files and delete only those that were x amount of days old. 

td

Check out the iFtpFindInit and iFtpFindNext functions in the Consolidated WIL Help file.  You use them to create a list of files that meet your date criteria because  iFtpFindNext returns create and modification date information. 

I completely forgot about iFtpFindNext's ability to retrieve create date information...
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade