I am struggling to download a file using ftplib. I have tried a variety of commands, and my logic seems to see the files that are on the FTP site and can return file sizes, but when I try to download them I get error messages. When I use a program with a GUI like WinSCP or Filezilla, I am able to download the file no problem, but I want to automate the process.
When I run the following, I expect to get the file downloaded to my working directory, but I get an error
from ftplib import FTP_TLS
ftps = FTP_TLS("ftp.xxxxx.com")
ftps.set_debuglevel(2)
ftps.set_pasv(True)
ftps.auth()
ftps.prot_p()
ftps.login(username, password)
with open('Hello.txt','wb') as fp:
ftps.retrbinary('RETR Hello.txt', fp.write) # [Errno 11] Resource temporarily unavailable
ftps.nlst() # [Errno 11] Resource temporarily unavailable
ftps.quit()
I tried running the logic on a different computer (thinking it is possible my current company is restricting the FTP connection, and get a different error
SSLEOFError: EOF occurred in violation of protocol (_ssl:c:1125)
This leads me to believe it is something to do with the "Verifying the Host Key or Certificate in Script" but I am not sure if there is anything I can do about it using ftplib.
EDIT: Logs below
*cmd* 'SIZE /.txt'
*put* 'SIZE /.txt\r\n'
*get* '213 12\n'
*resp* '213 12'
*cmd* 'SIZE /.xlsx'
*put* 'SIZE /.xlsx\r\n'
*get* '213 51304\n'
*resp* '213 51304'
*cmd* 'PBSZ 0'
*put* 'PBSZ 0\r\n'
*get* '200 PBSZ=0\n'
*resp* '200 PBSZ=0'
*cmd* 'PROT P'
*put* 'PROT P\r\n'
*get* '200 Protection level set to P\n'
*resp* '200 Protection level set to P'
*cmd* 'TYPE A'
*put* 'TYPE A\r\n'
*get* '200 Type set to A\n'
*resp* '200 Type set to A'
*cmd* 'PASV'
*put* 'PASV\r\n'
*get* '227 Entering Passive Mode\n'
*resp* '227 Entering Passive Mode '
*cmd* 'NLST'
*put* 'NLST\r\n'
*get* '150 Opening data channel for directory listing of "/"\n'
*resp* '150 Opening data channel for directory listing of "/"'
Traceback (most recent call last):
Cell In[186], line 27
ftps.nlst() # [Errno 11] Resource temporarily unavailable
File ~\AppData\Local\anaconda3\Lib\ftplib.py:553 in nlst
self.retrlines(cmd, files.append)
File ~\AppData\Local\anaconda3\Lib\ftplib.py:462 in retrlines
with self.transfercmd(cmd) as conn, \
File ~\AppData\Local\anaconda3\Lib\ftplib.py:393 in transfercmd
return self.ntransfercmd(cmd, rest)[0]
File ~\AppData\Local\anaconda3\Lib\ftplib.py:795 in ntransfercmd
conn = self.context.wrap_socket(conn,
File ~\AppData\Local\anaconda3\Lib\ssl.py:517 in wrap_socket
return self.sslsocket_class._create(
File ~\AppData\Local\anaconda3\Lib\ssl.py:1075 in _create
self.do_handshake()
File ~\AppData\Local\anaconda3\Lib\ssl.py:1346 in do_handshake
self._sslobj.do_handshake()
BlockingIOError: [Errno 11] Resource temporarily unavailable
Log from Filezilla:
Status: Resolving address of ftp.alndata.com
Status: Connecting to xxxxxxx...
Status: Connection established, initializing TLS...
Status: TLS connection established, waiting for welcome message...
Status: Logged in
Status: Retrieving directory listing...
Status: Directory listing of "/" successful
EDIT 3:
Logs from WinSCP that I think are relevant are below. I have been successful at getting the necessary files using both WinSCP and Filezilla
2023-08-07 15:16:48.181 227 Entering Passive Mode (104,214,57,236,85,240)
> 2023-08-07 15:16:48.181 MLSD
. 2023-08-07 15:16:48.181 Connecting to 104.214.57.236:22000 ...
. 2023-08-07 15:16:48.471 Session ID reused
. 2023-08-07 15:16:48.471 Using TLSv1.2, cipher TLSv1.2: ECDHE-RSA-AES256-GCM-SHA384, 2048 bit RSA, xxxx-xxx-xxxxx-xxx-SHA384 TLSv1.2 Kx=ECDH Au=RSA Enc=AESGCM(256) Mac=AEAD
< 2023-08-07 15:16:48.471 150 Opening data channel for directory listing of "/"
. 2023-08-07 15:16:48.471 TLS connection established
. 2023-08-07 15:16:48.489 type=file;modify=20230805132639;size=51304; ALN_MRI_Export.xlsx
. 2023-08-07 15:16:48.489 type=file;modify=20230806060018;size=51289; ALN_MRI_Export_2023-08-06_42bc69fc.xlsx
. 2023-08-07 15:16:48.489 type=file;modify=20230804150919;size=12; HelloMRI.txt
< 2023-08-07 15:16:48.529 226 Successfully transferred "/"
. 2023-08-07 15:16:48.529 Data connection closed