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

2024-05-21 17:09:31 发布

您现在位置: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