Batch file to delete old files from FTP server

Fri, 2008-11-28 21:32 by crazy4offroad · Forum/category:

Hello everyone! :)
I recently set up a Windows-based home video surveillance system and have it working perfectly (so far). I have an option in the software to send images to a free remote FTP server, just in case the video server itself was ever stolen the last images to arrive at the FTP server may help identify the offender. However, with the video server constantly sending images to the FTP server, eventually the alloted 250MB of disk space quickly runs out and no new images can be received.

I would like to find a batch file that could be ran by Task Scheduler twice a day to delete the older files from the FTP server, allowing recent images to be accepted. I figure this can be done by timestamp of the images, or even file count, but my experience with writing custom batch files is non-existent. I have been googling it for a few days now but my lack of understanding where to put what info to make it work is holding me back. None that I have found include obvious examples of the relavent information, like a name for the FTP server (example.ftp.com) or username/passwd (user/passwd). They just say something like "you have to put your information in the script," or "here you point to your FTP server" leaving me stumped. If anyone could guide me along to get this working I would greatly appreciate it! Thanks in advance.

No votes yet

Windows ftp

Fri, 2008-11-28 23:14 by admin

If you use the Windows ftp command, the simplest method to keep a small number of older backup files is to let ftp execute several rename commands like this:

delete file3
rename file2 file3
rename file1 file2
put file1

You can put these commands plus the logon and logoff information into a script file and start it with the command:

ftp -s:script.ftp

This assumes that your script file is named: script.ftp

It also assumes that this same script sends the latest image to the ftp server.

Another way is to get a local file listing of the remote ftp folder with the ftp command:

dir . filelist.txt

Or use some similar ftp command. Then transform the filelist file into the desired ftp command chain, using a local script program. This would be more demanding, but I see no simpler way to do exactly what you want, and I have no ready-made, complete solution. I only know that it is possible, relatively easy for a programmer, but still requires some work, perhaps a few hours for finding out the right commands, programming, and testing.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.