我正在尝试使用 Python 的 ftplib 传输文件。
def ftps_put_file(host, user, password, ftp_file_path, processed_file):
try:
context = ssl.create_default_context(ssl.Purpose.SERVER_AUTH, cafile='C:\\PATH\\TO\\SECURE.crt')
with FTP_TLS(host, user=user, passwd=password, context=context, timeout=10) as connection, open(processed_file, 'rb') as read_file:
connection.set_debuglevel(2)
connection.prot_p()
connection.cwd(ftp_file_path)
connection.storbinary(f"STOR {processed_file.name}", read_file)
except Exception as e:
print('Error occured in transporter.ftps_put_file: ' + str(e))
我可以毫无问题地连接到 FTP 主机,但在文件传输期间。连接超时启动并关闭连接,然后连接日志显示“425 数据通道因未满足最低带宽要求而超时。”我使用过其他 FTP 客户端(Filezilla、WinSCP),两者都能够连接到主机。
记录连接超时设置为 2 分钟
*cmd* 'PBSZ 0'
*put* 'PBSZ 0\r\n'
*get* '200 PBSZ command successful.\n'
*resp* '200 PBSZ command successful.'
*cmd* 'PROT P'
*put* 'PROT P\r\n'
*get* '200 PROT command successful.\n'
*resp* '200 PROT command successful.'
*cmd* 'CWD /'
*put* 'CWD /\r\n'
*get* '250 CWD command successful.\n'
*resp* '250 CWD command successful.'
*cmd* 'TYPE I'
*put* 'TYPE I\r\n'
*get* '200 Type set to I.\n'
*resp* '200 Type set to I.'
*cmd* 'PASV'
*put* 'PASV\r\n'
*get* '227 Entering Passive Mode (204,58,62,196,19,199).\n'
*resp* '227 Entering Passive Mode (204,58,62,196,19,199).'
*cmd* 'STOR text.txt'
*put* 'STOR text.txt\r\n'
*get* '125 Data connection already open; Transfer starting.\n'
*resp* '125 Data connection already open; Transfer starting.'
*cmd* 'QUIT'
*put* 'QUIT\r\n'
*get* '425 Data channel timed out due to not meeting the minimum bandwidth requirement.\n'
*resp* '425 Data channel timed out due to not meeting the minimum bandwidth requirement.'
连接超时设置为 60 秒或更短的日志 这个序列看起来很奇怪,因为连接退出然后给出 226 Transfer Completed。不是应该说传输完成然后退出吗?
*cmd* 'PBSZ 0'
*put* 'PBSZ 0\r\n'
*get* '200 PBSZ command successful.\n'
*resp* '200 PBSZ command successful.'
*cmd* 'PROT P'
*put* 'PROT P\r\n'
*get* '200 PROT command successful.\n'
*resp* '200 PROT command successful.'
*cmd* 'CWD /'
*put* 'CWD /\r\n'
*get* '250 CWD command successful.\n'
*resp* '250 CWD command successful.'
*cmd* 'TYPE I'
*put* 'TYPE I\r\n'
*get* '200 Type set to I.\n'
*resp* '200 Type set to I.'
*cmd* 'PASV'
*put* 'PASV\r\n'
*get* '227 Entering Passive Mode (204,58,62,196,20,46).\n'
*resp* '227 Entering Passive Mode (204,58,62,196,20,46).'
*cmd* 'STOR text.txt'
*put* 'STOR text.txt\r\n'
*get* '125 Data connection already open; Transfer starting.\n'
*resp* '125 Data connection already open; Transfer starting.'
*cmd* 'QUIT'
*put* 'QUIT\r\n'
*get* '226 Transfer complete.\n'
*resp* '226 Transfer complete.'
请您参考如下方法:
我遇到了同样的问题。我调试通信的选项是有限的(不能完全访问客户端,不能访问服务器),但在我看来,当客户端关闭连接时,服务器端没有发送确认(如此处所述 - https://enterprisedt.com/questions/index.php/2580/ftpexception-425-data-channel-timed-out-due-to-not-meeting?start=10 )
我在客户端使用 Linux Python 3.7 标准库 (ftplib.FTP_TLS),在服务器端有 Windows FTP 服务。
我现在没有满意的解决方案,我只是通过检查上传文件的大小来确保文件上传正确。我被告知 Windows 上的 FileZilla 客户端可以正确处理此问题(即没有错误,但我无法验证)。
