Reputation: 7739
So I am working with ftplib in python 2.7 to connect to a remote FTP server (from another server) in order to download a file. When I execute the RETR command, it throws:
self.get_connection().retrbinary("RETR " + source, open(destination, 'wb').write)
File "/usr/lib/python2.7/ftplib.py", line 414, in retrbinary
conn = self.transfercmd(cmd, rest)
File "/usr/lib/python2.7/ftplib.py", line 376, in transfercmd
return self.ntransfercmd(cmd, rest)[0]
File "/usr/lib/python2.7/ftplib.py", line 335, in ntransfercmd
conn = socket.create_connection((host, port), self.timeout)
File "/usr/lib/python2.7/socket.py", line 575, in create_connection
raise err
socket.error: [Errno 113] No route to host
Now my code is working fine in another server, but in this one it seems not. So I tried ping x.x.x.x
(it works), I use telnet x.x.x.x 21
(it works), ftp x.x.x.x
(it works!). Then I went to the firewall (on both servers) and allowed all in & out traffic and still getting the same error...
Any ideas ?! (As I said this is working fine on a third server... and it seems that the login command works fine but not the RETR)
Edit:
This is a sample of commands executed directly in ftp
Upvotes: 0
Views: 1842
Reputation: 123270
... to connect to a remote FTP server
According to your description you connect to a remote server but the server shows that it uses private IP addresses. My guess is that the address the server is aware of (10.0.0.8) is not the address you use to connect to the server, i.e. that the server is behind some router and there is port forwarding or address translation done.
Unfortunately FTP does not really work when one of the parties is behind a router. You might play around with passive and active mode when client is behind router (passive) or server (active). But if both are behind a router you have usually lost.
Upvotes: 1
Reputation: 736
Are you trying to connect to a FTPES server?
Try this:
from ftplib import FTP_TLS
creds = [
'host', 'username',
'password']
ftps = FTP_TLS(*creds)
ftps.prot_p()
ftps.retrlines('LIST')
This should list the files present in the directory
you can than use something like,
ftps.retrbinary("RETR " + 'test.csv' ,open('test.csv', 'wb').write)
to retrieve the file from the server and writing it locally.
Upvotes: 0