我需要将一个包含子目录和文件的目录上传到FTP服务器上。但是我似乎无法做到正确上传。我希望能够按照原样上传整个目录,包括其中的子目录和文件。
ftp = FTP()
ftp.connect('host',port)
ftp.login('user','pass')
filenameCV = "directorypath"
for root,dirnames,filenames in os.walk(filenameCV):
for files in filenames:
print(files)
ftp.storbinary('STOR ' + files, open(files,'rb'))
ftp.quit()
directorypath
是您的本地基目录,并且您将所有内容上传到FTP服务器的根目录。否则,在上传之前,您必须添加一个ftp.cwd(...)
。 - jojonas