Here's what I want to accomplish:
- Login to TABS FTP System - OPEN ftptabs.dtn.com
- Send User name = TABSN_[Seller Number]X[Login]
- Send Password
- Send ADMLOD file to IMPORT Directory = Put ./IMPORT/
- Process ADMLOD file and get response file = get ./IMPORT// /
- 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!