在使用Python中的ftplib上载文件之前更改服务器上的目录
作者:互联网
我有这个代码,但我无法弄清楚如何在上传文件之前更改服务器上的目录.
谁能帮我吗?
import ftplib
import os
server = 'enter your servername here'
username = 'root'
password = 'passowrd'
myFTP = ftplib.FTP(server, username, password)
myPath = r'C:\path_of_the_folder_goes_here'
def uploadThis(path):
files = os.listdir(path)
os.chdir(path)
for f in files:
if os.path.isfile(path + r'\{}'.format(f)):
fh = open(f, 'rb')
myFTP.storbinary('STOR %s' % f, fh)
fh.close()
elif os.path.isdir(path + r'\{}'.format(f)):
myFTP.mkd(f)
myFTP.cwd(f)
uploadThis(path + r'\{}'.format(f))
myFTP.cwd('..')
os.chdir('..')
uploadThis(myPath)
解决方法:
myFTP.cwd('/remote/path')
在你打电话之前
uploadThis(myPath)
标签:python,ftp,ftplib 来源: https://codeday.me/bug/20191007/1865909.html