使用python 我用這個代碼,但它不工作了如何從一個文件夾使用python
ftp=FTP("host")
ftp.login("user name","password")
def downloadFiles(path,destination):
try:
ftp.cwd(path)
#clone path to destination
ftp.dir(destination)
#~ os.mkdir(destination[0:len(destination)-1]+path)
print destination[0:len(destination)-1]+path+" built"
except OSError:
#folder already exists at destination
pass
except ftplib.error_perm:
#invalid entry (ensure input form: "/dir/folder/something/")
print "error: could not change to "+path
sys.exit("ending session")
filelist=ftp.nlst()
for file in filelist:
try:
#this will check if file is folder:
ftp.cwd(path+file+"/")
#if so, explore it:
downloadFiles(path+file+"/",destination)
except ftplib.error_perm:
#not a folder with accessible content
#download & return
#~ os.chdir(destination[0:len(destination)]+path)
#possibly need a permission exception catch:
#~ ftp.retrbinary("RETR "+ file, open(ftp.path.join(destination,file),"wb").write)
ftp.storlines("STOR "+file, open(ftp.dir(destination, file),'r'))
print file + " downloaded"
return
歡迎來到Stackoverflow!準確地說:a)到目前爲止你所嘗試的是什麼(展示一個**最小完整的可驗證示例**)b)你卡在哪裏(再次顯示代碼)。 – SuperSaiyan
嘗試'ftplib'模塊和'rename()'函數。 – furas
@steven Barnes請參閱下面的問題我使用該代碼 –