FTP上传没有数据错误

时间:2017-10-31 17:12:29

标签: ftp ftplib

我得到一个奇怪的错误,只有当我尝试在Linux服务器上运行此代码时才出现,但它在我的本地Mac上运行完美。我不确定是否有其他人遇到过这个问题,可以给我见解。

 import ftplib
 import sys, os

 files_to_drop = set()
 server = ""
 username = ""
 password = ""
 ftp_connection = ftplib.FTP(server, username, password)
 remote_path = "/incoming/"
 ftp_connection.cwd(remote_path)
 local_path = '/var/www/analytics/'

 def deliver_via_ftp():
    fh = open(local_path + files_to_drop[0], 'rb')
    ftp_connection.storbinary('STOR {}'.format(files_to_drop[0]), fh)
    fh.close()

我在Linux机器上收到的错误如下:

*cmd* 'CWD /incoming/'
*put* 'CWD /incoming/\r\n'
*get* '250 Directory successfully changed.\n'
*resp* '250 Directory successfully changed.'
starting to drop files.
*cmd* 'TYPE I'
*put* 'TYPE I\r\n'
*get* '500 OOPS: vsf_sysutil_recv_peek: no data\n'
*resp* '500 OOPS: vsf_sysutil_recv_peek: no data'
Traceback (most recent call last):
  File "manage_batches.py", line 258, in <module>
    m.run()
  File "manage_batches.py", line 253, in run
    self.__deliver_via_ftp()
  File "manage_batches.py", line 215, in __deliver_via_ftp
    self.ftp_connection.storbinary('STOR {}'.format(file_name), fh)
  File "/usr/lib/python3.5/ftplib.py", line 502, in storbinary
    self.voidcmd('TYPE I')
  File "/usr/lib/python3.5/ftplib.py", line 277, in voidcmd
    return self.voidresp()
  File "/usr/lib/python3.5/ftplib.py", line 250, in voidresp
    resp = self.getresp()
  File "/usr/lib/python3.5/ftplib.py", line 245, in getresp
    raise error_perm(resp)
ftplib.error_perm: 500 OOPS: vsf_sysutil_recv_peek: no data

我在这里发现了一个关于问题的线程(https://github.com/mscdex/node-ftp/issues/50),但似乎指出反复打开和关闭连接。我为所有文件重复使用相同的连接,它可以在我的Mac上运行。

Mac上的调试跟踪:

*cmd* 'CWD /incoming/'
*put* 'CWD /incoming/\r\n'
*get* '250 Directory successfully changed.\n'
*resp* '250 Directory successfully changed.'
*cmd* 'TYPE I'
*put* 'TYPE I\r\n'
*get* '200 Switching to Binary mode.\n'
*resp* '200 Switching to Binary mode.'
*cmd* 'PASV'
*put* 'PASV\r\n'
*get* '227 Entering Passive Mode (<hidden IP>,11,133).\n'
*resp* '227 Entering Passive Mode (<hidden IP>,11,133).'
*cmd* 'STOR 11062017_0812_AM.txt'
*put* 'STOR 11062017_0812_AM.txt\r\n'
*get* '150 Ok to send data.\n'
*resp* '150 Ok to send data.'
*get* '226 Transfer complete.\n'
*resp* '226 Transfer complete.'
file dropped /Users/f/Desktop/bucket/11062017_0812_AM.txt

有人能指出我正确的方向吗?

谢谢

编辑:我清理了代码以删除类结构,并将调试输出集添加到级别2。

0 个答案:

没有答案