带有命令到服务器的Python ftplib上载文本文件:错误502命令无法识别

时间:2016-12-07 16:55:16

标签: python ftp

这就是我想要完成的事情:

  1. 登录TABS FTP系统 - 打开ftptabs.dtn.com
    1. 发送用户名= TABSN_ [卖家编号] X [登录]
    2. 发送密码
    3. 将ADMLOD文件发送到IMPORT Directory = Put ./IMPORT /
    4. 处理ADMLOD文件并获取响应文件= get ./IMPORT// /
    5. 结束会话=退出
  2. 以下是vanilla FTP脚本中的代码:

    OPEN FTPTABS.DTN.COM
    TABSN_999XTEST1234
    TEST8547
    PUT ADMCON.TXT ./IMPORT/ADMCONS1105.TXT
    GET ./IMPORT ADMCONS1105.TXT ADMCONS1105RESPONSE.TXT
    QUIT
    

    Python代码:

    def test_upload():
        ftp = FTP('catftptabs.dtn.com')
        ftp.login(user=username, passwd=password)
    
        # Put <Your local file name> ./IMPORT/<File name>
        ftp.putcmd('ADMCON.TXT ./IMPORT/ADMCONS1105.TXT')
        ftp.sendcmd('GET ./IMPORT ADMCONS1105.TXT ADMCONS1105RESPONSE.TXT')
        ftp.quit()
    

    似乎打破了ftp.sendcmd(...)行,这里是错误消息:

    In[84]: ftp.putcmd('ADMCON.TXT ./IMPORT/ADMCONS1105.TXT')
    In[85]: ftp.sendcmd('GET ./IMPORT ADMCONS1105.TXT ADMCONS1105RESPONSE.TXT')
    Traceback (most recent call last):
      File "/usr/local/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 2881, in run_code
        exec(code_obj, self.user_global_ns, self.user_ns)
      File "<ipython-input-85-8b7bcc0b14c2>", line 1, in <module>
        ftp.sendcmd('GET ./IMPORT ADMCONS1105.TXT ADMCONS1105RESPONSE.TXT')
      File "/usr/local/Cellar/python3/3.5.2_1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ftplib.py", line 272, in sendcmd
        return self.getresp()
      File "/usr/local/Cellar/python3/3.5.2_1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ftplib.py", line 245, in getresp
        raise error_perm(resp)
    ftplib.error_perm: 502 Command not recognized or allowed.
    

    非常感谢任何帮助!

0 个答案:

没有答案