我需要将相同的本地文件上传到FTP服务器上的不同目标文件名中。不是Python的专家在做这样的功能。最好使用Python2.7和任何好的代码示例。谢谢。
谢谢你,林
发布于 2016-03-11 10:04:53
以下几点应该能让你开始:
from ftplib import FTP
hosts = [('10.1.0.1', 'abc', '123'), ('10.1.0.2', 'abc', '123')]
local_file = r'/my_folder/my_file.txt'
remote_file = 'my_file.txt'
for host, name, password in hosts:
f = FTP(host, name, password)
f.cwd('my_remote_folder')
with open(local_file, 'rb') as f_local:
f.storbinary('STOR {}'.format(remote_file), f_local)
print "{} - done".format(host)
f.quit()这将将my_file.txt从单个源位置上载到hosts列表中的每个主机。它将文件上载到每个服务器上的相同位置。
https://stackoverflow.com/questions/35935771
复制相似问题