简体   繁体   English

如何通过python同步两个ftp服务器

[英]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. 我有两个FTP服务器a和b,我需要将文件从服务器复制到b服务器。 Downloading the file from a and upload to b is too complicate, I want to write a script by python to do this on my desktop, just type the command below it will do the job. 从a下载文件并上传到b太复杂了,我想用python编写一个脚本来在我的桌面上执行此操作,只需键入下面的命令即可完成工作。

 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. 但经过一些谷歌,仍然找不到像Dropbox一样同步两个ftp服务器的好方法。 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. 首先,你有http://www.csync.org/这是一种rsync(但由于rsync只适用于SSH而不是FTP),但适用于HTTP / FTP传输。

If you don't like that option there's always "lftp" or "curlftpfs", stackoverflow has a sister-site which provides your answer: 如果您不喜欢该选项,那么总是有“lftp”或“curlftpfs”,stackoverflow有一个姐妹站点提供您的答案:

https://serverfault.com/questions/24622/how-to-use-rsync-over-ftp 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 如果你没有给你什么,那么你总是在python中有ftplib: 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. 使用sys.argv []获取输入/输出文件,也可以使用source-host和desition。

Enjoy! 请享用! :) :)

This sounds like a job for rsync to me. 这听起来像是rsync给我的工作。 As the name lets suggest, it can recursively sync files and directories (also with compression and other stuff). 正如名称所暗示的那样,它可以递归地同步文件和目录(也包括压缩和其他内容)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM