Copy all files from one FTP directory to another

2019-05-30 12:49发布

问题:

I have to copy all existing files inside one ftp directory to another ftp directory on another server. I have not had any experience writing scripts - so any help with this would be great.

I'm wondering if its possible to write this script so that it happens every day at a specific time?

What software/ language should I use for this? Python is a well renowned one, but I want to make sure it suits my requirements.

Can someone give me a basic code implementation for how to do it?

Thanks in advance

回答1:

In the end you will probably end up downloading the whole directory to a local machine and re-uploading it to the other, as there's generally no way to copy files between directories in FTP.
See FTP copy a file to another place in same FTP.

You will find plenty of examples for downloading and uploading. You do not even need a scripting language. Simply use some command-line FTP client.

For example with WinSCP FTP client, you can use the following batch file (.bat):

winscp.com /log=copy.log /command ^
    "open ftp://username:password@ftp.example.com/" ^
    "get /source/remote/path/* C:\temporary\local\path\" ^
    "put C:\temporary\local\path\* /destination/remote/path/" ^
    "exit"

See the guide to Automating file transfers to and from FTP server.

(I'm the author of WinSCP)



标签: python shell ftp