通过SSL / TLS的FTP / FXP服务器到服务器传输

时间:2018-12-04 18:18:57

标签: python ftp ftplib

我想在两个(支持​​FXPable)FTP服务器之间建立连接,并传输一个包含子文件夹和文件的文件夹。

作为一个示例,我想将整个/www/xy.com从服务器1复制(FXP-站点到站点)到服务器2上的/www/xy.com,但是我不知道该怎么做。 / p>

我在PyPI上找到了一个有趣的模块,称为“ ftpext”,但我无法正确理解它。该模块包括FXP和PRET支持。还有我想用的。所以也许有人可以帮助我。如果您可以采用其他方式,则不需要该模块。

这里是链接:

我的脚本应该可以:

usage: %s SERVER1 PORT1 USER1 PASS1 PATH_TO_FOLDER1 SERVER2 PORT2 USER2 PASS2 PATH_TO_DESTINATION_FOLDER

这是我当前脚本的输出:

CONNECTiON ESTABLiSHED OVER SSL/TLS TO SERVER 1: *.*.*.*

switched to secure data connection

Changed directory on Server1 successfully to: www

CONNECTiON ESTABLiSHED OVER SSL/TLS TO SERVER 2: *.*.*.*

switched to secure data connection

Changed directory on Server2 successfully to: www

这是我的脚本(它非常快速且肮脏,没有错误处理):

from ftplib import FTP_TLS
import sys

# SECURE CONNECT TO FTP1 OVER TLS/SSL

ftps1 = FTP_TLS
ftps1 = FTP_TLS.port = sys.argv[2]
ftps1 = FTP_TLS('%s' % sys.argv[1])
ftps1.login(sys.argv[3], sys.argv[4])
print("CONNECTiON ESTABLiSHED OVER SSL/TLS TO SERVER 1: %s" % sys.argv[1])
print()
ftps1.prot_p()
print("switched to secure data connection")
print()
ftps1.cwd(sys.argv[5])
print("Changed directory on Server1 successfully to: %s" % sys.argv[5])
print()

# SECURE CONNECT TO FTP2 OVER TLS/SSL

ftps2 = FTP_TLS
ftps2 = FTP_TLS.port = sys.argv[7]
ftps2 = FTP_TLS('%s' % sys.argv[6])
ftps2.login(sys.argv[8], sys.argv[9])
print("CONNECTiON ESTABLiSHED OVER SSL/TLS TO SERVER 2: %s" % sys.argv[6])
print()
ftps2.prot_p()
print("switched to secure data connection")
print()
ftps2.cwd(sys.argv[10])
print("Changed directory on Server2 successfully to: %s" % sys.argv[10])

1 个答案:

答案 0 :(得分:0)

我假设您正在寻找FTPExt.fxp_toFTPExt.secure_fxp_to方法:

ftp1 = FTPExt(host1, port1, user1, password1, True)
ftp2 = FTPExt(host2, port2, user2, password2, True)

ftp1.fxp_to(path1, ftp2, path2)