'Python: ftputil上传18mb文件只能上载36kb'

2024-10-03 17:25:14 发布

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

弗蒂尔就是炸弹。。。。几乎!

我的召唤主机.上传下面的工作很好的小文本文件。对于较大的文件(我主要处理9-20GB的文件),没有异常,也没有错误,但只有10-40kb被上传。

从同一个客户机我可以上传大文件罚款使用filezilla客户端,所以我知道没有这类问题。filezilla客户端和ftputil都使用主动模式ftp(防火墙有ftp链接,其中一个防火墙导致了被动模式的问题)

如何解决?

class MySession(ftplib.FTP):

    def __init__(self, ftpServer, ftpUser, ftpPassword, ftpPort):
        ftplib.FTP.__init__(self)
        self.set_debuglevel(ftpDebugLevel)
        self.set_pasv(False)
        self.connect(ftpServer, ftpPort)
        self.login(ftpUser, ftpPassword)

host = ftputil.FTPHost(ftpServer, ftpUser, ftpPassword, ftpPort, session_factory=MySession) 

file = '18MBfile.zip'
print('ftp file to upload is:' + file + ' -- ' + join(dirpath,file) + ' -- ' + os.path.basename(file))
upload = host.upload(join(dirpath,file), destDir + os.path.basename(file))  # local, remote -- for remote: extract just file name from full path+filename

Tags: 文件pathself客户端ftpfileupload防火墙