本文介紹了如何將文件從 FTP 文件夾移動和替換到同一 FTP 中的另一個文件夾的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在嘗試將 FTP 位置中的一些 XML 文件移動到同一 FTP 中的另一個位置.我嘗試了以下代碼,但它不起作用.
I am trying to move some XML files in an FTP location to another location in the same FTP. I tried with the following code, but it doesn't work.
def ftpPush(filepathSource, filename, filepathDestination):
try:
ftp = FTP(ip, username, password)
ftp.cwd(filepathDestination)
ftp.storlines("STOR "+filename, open(filepathSource, 'r'))
ftp.quit()
for fileName in os.listdir(path):
if fileName.endswith(".xml"):
ftpPush(filepathSource, filename, filepathDestination)
except Exception, e:
print str(e)
finally:
ftp.close()
推薦答案
要移動文件,請使用 FTP.rename
.
To move a file use the FTP.rename
.
假設 filepathSource
和 filepathDestination
都是遠程文件,你這樣做:
Assuming that the filepathSource
and the filepathDestination
are both remote files, you do:
ftp.rename(filepathSource, filepathDestination)
這篇關于如何將文件從 FTP 文件夾移動和替換到同一 FTP 中的另一個文件夾的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!