Need Batch script in windows to upload files to a particular ftp location [closed]
I have several backup files in a location, say C:\backup_folder\...
Now I need a batch script (.bat
), so that all files under C:\backup_folder\*.zip
will be moved to a particular FTP location (ftp.mysite.com
).
Also, if the file already exists on the FTP site, they must be overwritten with the new file... Can anyone show me a script that performs these backups?
The trick with automated file xfer with Windows (for me at least) has always been using the correct commandline upload tool. For ME, when I've wanted a shell-scriptable tool, that usually ends up being rsync from cygwin. But since you asked about Windows batch with FTP (as opposed to a safer, more reliable solution, you might want to try using a Windows build of wput
Since you want to overwrite the file each time, you would use the -u (re-upload) option. I found wput supported most of the FTP options I wanted, and should handle this job. Although I absolutely agree with your desire to always re-upload the entire file, you CAN set it for a few optimizations that you might find handy if you're uploading over a slow link, like using a timestamp comparison to decide if you don't need to upload (-N). Another option backup scripts MAY want is to remove your source file after a successful upload (-R option).
I just feel it's wise to point out that FTP isn't nearly as reliable a protocol as I would want in a backup script ... but your desire to always re-upload the file(s) is a good one.
精彩评论