首页 > 解决方案 > 如何使用python通过FT上传许多文件?

问题描述

我有很多文件(可能是大量文件),我想上传到我的 FTP 服务器。

我应该如何实施?通过只使用一个连接直到错误或每次关闭/打开..我还需要检查 FTP 服务器是否活动。我使用 ftplib。

from ftplib import FTP 

def ftp_upload(remotefile):
  with open(localfile, 'rb') as f:  
    ftp.storlines('STOR %s' % remotefile, f)  

  #ftp.close()


ftp = FTP()
ftp.set_debuglevel(2)

retry = False

while True:
    try:
        if retry:
            /* find list of files * remote_path="some_file"/
            ftp_upload(remote_path)
        else:
            ftp.connect('host', port) 
            ftp.login('user','pass')
            retry=True

    except Exception as e:
        print("error({0}): {1}".format(e.errno, e.strerror))
        rint("Retrying...")
        retry = False

标签: pythonftp

解决方案


推荐阅读