【发布时间】:2015-03-16 23:24:32
【问题描述】:
Python 在上传大于 8192 字节的文件时失败。例外只是“得到了超过 8192 个字节”。有没有上传大文件的解决方案。
try:
ftp = ftplib.FTP(str_ftp_server )
ftp.login(str_ftp_user, str_ftp_pass)
except Exception as e:
print('Connecting ftp server failed')
return False
try:
print('Uploading file ' + str_param_filename)
file_for_ftp_upload = open(str_param_filename, 'r')
ftp.storlines('STOR ' + str_param_filename, file_for_ftp_upload)
ftp.close()
file_for_ftp_upload.close()
print('File upload is successful.')
except Exception as e:
print('File upload failed !!!exception is here!!!')
print(e.args)
return False
return True
【问题讨论】:
-
文件是否包含文本?如果没有,您可能希望以二进制模式打开并使用
ftp.storbinary()。
标签: python file-upload ftp