开发者

how to sync two ftp server by python

I have two FTP server a and b, I need to copy files from a server to b server. Downloading the file from a and upload to b is too complicate, I want to write a 开发者_如何学Pythonscript by python to do this on my desktop, just type the command below it will do the job.

 python syncftp.py a.com(source server) folder(folder name in source server) 
        b. com(destination server) folder(destination folder name) 

but after some google, still can't find a good way to sync two ftp server just like dropbox. Is there any other way to do this? thanks.


For starters, you have http://www.csync.org/ which is sort of a rsync (but since rsync only works with SSH and not FTP) but for HTTP/FTP transfers.

If you don't like that option there's always "lftp" or "curlftpfs", stackoverflow has a sister-site which provides your answer:

https://serverfault.com/questions/24622/how-to-use-rsync-over-ftp

if THAT doesn't give you anything, well then you always have ftplib in python: http://docs.python.org/library/ftplib.html

from ftplib import FTP
ftpretr = FTP('get.ftp.com')   # connect to host, default port
ftpretr.login()               # user anonymous, passwd anonymous@
ftpretr.retrbinary('RETR README', open('README', 'wb').write)
ftpretr.quit()
ftpsend = FTP('send-to.ftp.com','login','password')
ftpsend.storbinary('STOR todo.txt', open('README','rb'))
ftpsend.quit()

Now i can't help you more then that tbh without doing everything for you and i'm guessing you want to learn? use sys.argv[] to fetch input/output files and also for source-host and desition perhaps.

Enjoy! :)


This sounds like a job for rsync to me. As the name lets suggest, it can recursively sync files and directories (also with compression and other stuff).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜