ftp.retrbinary(ftplib)上的错误501

时间:2014-12-09 00:20:06

标签: python python-2.7 ftplib

我编写脚本来检查FTP目录并下载新文件。这是代码的一部分:

from ftplib import FTP
import os

ftp = FTP(ftp_lance)
ftp.login(login, password)
ftp.cwd('xxxxxx')

FTP_list = ftp.nlst()

lista_diferenca = [file for file in FTP_list if file not in local_list]

for file in lista_diferenca:
    local_filename = os.path.join(cache, file)
    ftp.retrbinary('REST ' + file, open(local_filename, 'wb').write)

当我运行它时,我收到此错误消息:

Traceback (most recent call last):
  File "D:\Scripts\Istari\Radagast\Radagast.py", line 44, in <module>
    ftp.retrbinary('REST tabela14_pag5.pdf', open(local_filename, 'wb').write)
  File "D:\Portable Python 2.7.6.1\App\lib\ftplib.py", line 414, in retrbinary
    conn = self.transfercmd(cmd, rest)
  File "D:\Portable Python 2.7.6.1\App\lib\ftplib.py", line 376, in transfercmd
    return self.ntransfercmd(cmd, rest)[0]
  File "D:\Portable Python 2.7.6.1\App\lib\ftplib.py", line 339, in ntransfercmd
    resp = self.sendcmd(cmd)
  File "D:\Portable Python 2.7.6.1\App\lib\ftplib.py", line 249, in sendcmd
    return self.getresp()
  File "D:\Portable Python 2.7.6.1\App\lib\ftplib.py", line 224, in getresp
    raise error_perm, resp
error_perm: 501 Bad parameter. Numeric value required

我检查了几个搜索此类错误的网站,但没有找到任何内容。似乎我的后续操作已被破坏,但参数看起来正确(首先是&#39; Rest&#39; +文件,然后是回调函数)。

关于我的错误的一些想法?

1 个答案:

答案 0 :(得分:0)

您需要指定FTP命令RETR,而不是REST

ftp.retrbinary('RETR ' + file, open(local_filename, 'wb').write)