如何将文件从FTP文件夹移动和替换到同一FTP中的另一个文件夹

2024-03-28 21:04:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我是Python新手。我正在尝试将ftp位置中的一些xml文件移到同一个ftp中的另一个位置。我尝试使用以下代码,但它不起作用。在

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()

Tags: 文件代码ipdefusernameftpxmlfilename
1条回答
网友
1楼 · 发布于 2024-03-28 21:04:20

要移动文件,请使用^{}。在

假设filepathSourcefilepathDestination都是远程文件,那么可以:

ftp.rename(filepathSource, filepathDestination)

相关问题 更多 >