0

Here's what I want to accomplish:

  1. Login to TABS FTP System - OPEN ftptabs.dtn.com
    1. Send User name = TABSN_[Seller Number]X[Login]
    2. Send Password
    3. Send ADMLOD file to IMPORT Directory = Put ./IMPORT/
    4. Process ADMLOD file and get response file = get ./IMPORT// /
    5. End Session = QUIT

Here is the code for this in vanilla FTP script:

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

Python code:

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()

It seems to break with the ftp.sendcmd(...) line, here is the error message:

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.

Any help would be much appreciated!

  • isn't it `RETRIEVE` ? – Jean-François Fabre Dec 07 '16 at 16:58
  • The plain FTP code for the task is correct and I have verified that it works. Are you suggesting a change to the python code? – Graham Duncan Dec 07 '16 at 17:28
  • Your code is total nonsense. The `putcmd` is not for uploading files, it's for sending a raw FTP command. The same for `sendcmd`. There's no `GET` FTP protocol command. Etc, etc, etc. – Martin Prikryl Dec 07 '16 at 18:35
  • @MartinPrikryl Really? Cause it seems to work for me...don't call my code total nonsense when I am asking for help. That is not productive ftp> get ./IMPORT/ADMCONS1105.txt ADMCONS1105RESPONSE.txt local: ADMCONS1105RESPONSE.txt remote: ./IMPORT/ADMCONS1105.txt 229 Entering Extended Passive Mode (|||51207|) 150 BINARY data connection for (172.17.208.152:51207) (215 bytes). 100% |***********************************| 307 3.70 MiB/s --:-- ETA 226 Transfer complete. 307 bytes received in 00:00 (1.44 MiB/s) – Graham Duncan Dec 07 '16 at 20:39
  • You mistake FTP protocol commands with commands of common FTP command-line client. These are completely different. See the question I've linked above for a correct code to upload a file with ftplib. – Martin Prikryl Dec 07 '16 at 22:09

0 Answers0