Goodmorning everyone, I'm trying to connect with python to the ip address of my explicit FTP server on TLS ...
from ftplib import FTP_TLS
def Ftp_Transfer():
ftps = FTP_TLS('ftp://username@IP:PORT')
ftps.login(user='username', passwd='pass')
But I got this error:
Traceback (most recent call last):
File "C:\Users\Utente\Desktop\Lavori\Organizzazione\LOG_Windows.p
y", line 13, in Ftp_Transfer
ftps = FTP_TLS('ftp://username@IP:PORT')
File "C:\Users\Utente\Anaconda3\lib\ftplib.py", line 745, in __init__
FTP.__init__(self, host, user, passwd, acct, timeout, source_address)
File "C:\Users\Utente\Anaconda3\lib\ftplib.py", line 117, in __init__
self.connect(host)
File "C:\Users\Utente\Anaconda3\lib\ftplib.py", line 152, in connect
source_address=self.source_address)
File "C:\Users\Utente\Anaconda3\lib\socket.py", line 707, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "C:\Users\Utente\Anaconda3\lib\socket.py", line 748, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11003] getaddrinfo failed
Can someone help me?
(I bring up FileZilla because that is the only server we consistantly have problems with)
I do know that FTP_TLS does not support FileZilla servers running on modern configurations - There has been work to hack the FTP_TLS implementation, but even that doesn't work on 2020 FileZilla default configs.
We ended up running lftp from the commant-line, through Python. Please note this is a HORRIBLE idea (security vulnerability) if any input comes from an un-trusted user.
Example of our implementation below. Works for Implicit FTP over TLS:
import os
# add `;set xfer:clobber yes` to -e arguments to enable file overwrite
os.system('lftp -u %(username)s,%(password)s -e "set ssl:verify-certificate no;get %(remote_filename)s -o %(local_filename)s;exit" ftps://%(host)s' % {
'username': USERNAME,
'password': PASSWORD,
'host': HOST,
'remote_filename': '/filename-to-download.txt',
'local_filename': '/path/to/filename.txt',
}
)
If you don't have lftp installed, on Ubuntu you can simply run:
apt install lftp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With