I am trying to connect to a FTP server using the standard Python FTP library (ftplib). I am using Python 3.8.
The account used to access the FTP server has a password containing the escape character \ which is automatically doubled once read by ftplib.
So in my password, among all the characters, I have one \ but ftplib sends \ instead. The password is automatically generated according a security policy so I cannot request to avoid this kind of character.
How can I tell to ftplib to take the string as is?
I already tried r'mypwd' or r'{}'.format(mypwd) without any success. Each time I look in the ftp object in the debug I see the \ has been doubled.
Thank you for the help!
EDIT:
Example:
from ftplib import FTP_TLS
addr = '192.168.1.23'
usr = 'ftpuser'
pwd = '3Hc]85}Lxqy\%I+bc1(T'
ftp = FTP_TLS()
ftp.set_debuglevel(2)
ftp.connect(host=addr, port=21)
ftp.login(user=usr, passwd=pwd)
When you set a breakpoint on ftp = FTP(), you can see the password has been altered
EDIT 2: Log from Filezilla:
Status: Connecting to 192.168.1.23:21...
Status: Connection established, waiting for welcome message...
Status: Insecure server, it does not support FTP over TLS.
Status: Server does not support non-ASCII characters.
Status: Logged in
Status: Retrieving directory listing...
Status: Directory listing of "/home/ftpuser" successful
16:50:39 Status: Disconnected from server
16:50:39 Status: Connecting to 192.168.1.23:21...
16:50:39 Status: Connection established, waiting for welcome message...
16:50:39 Response: 220 (vsFTPd 3.0.3)
16:50:39 Command: AUTH TLS
16:50:39 Response: 530 Please login with USER and PASS.
16:50:39 Command: AUTH SSL
16:50:39 Response: 530 Please login with USER and PASS.
16:50:39 Status: Insecure server, it does not support FTP over TLS.
16:50:39 Command: USER ftpuser
16:50:39 Response: 331 Please specify the password.
16:50:39 Command: PASS ********************
16:50:39 Response: 230 Login successful.
16:50:39 Status: Server does not support non-ASCII characters.
16:50:39 Status: Logged in
16:50:39 Status: Retrieving directory listing...
16:50:39 Command: PWD
16:50:39 Response: 257 "/home/ftpuser" is the current directory
16:50:39 Status: Directory listing of "/home/ftpuser" successful
Log from ftplib:
*get* '220 (vsFTPd 3.0.3)\n'
*resp* '220 (vsFTPd 3.0.3)'
*cmd* 'AUTH TLS'
*put* 'AUTH TLS\r\n'
*get* '530 Please login with USER and PASS.\n'
*resp* '530 Please login with USER and PASS.'
Traceback (most recent call last):
File "/xxxxxx/test.py", line 10, in <module>
ftp.login(user=usr, passwd=pwd)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/ftplib.py", line 739, in login
self.auth()
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/ftplib.py", line 747, in auth
resp = self.voidcmd('AUTH TLS')
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/ftplib.py", line 282, in voidcmd
return self.voidresp()
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/ftplib.py", line 255, in voidresp
resp = self.getresp()
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/ftplib.py", line 250, in getresp
raise error_perm(resp)
ftplib.error_perm: 530 Please login with USER and PASS.