问题描述
我正在尝试将 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)
丶浅陌丶