I created a complete FTP library some time ago. Now I want to connect to an SFTP server. As far as I found out in my research this is not possible using ftplib. Nevertheless I tried to connect to an SFTP only server and it worked without any problems. No error and no exception!
Now I'm a bit confused as I'm not sure if this really is a secure connection (which is important for this application). Especially as I could not find similar cases online. Which brings me to the following questions:
This is the base code I use:
server = 'host-adress'
user = 'username'
password='password'
ftp = FTP(server)
ftp.login(user,password)
All operations like up and downloading files work just fine.
According to my host the server is configured as SFTP.
Logging returns this as result:
*cmd* 'USER username'
*put* 'USER username\r\n'
*get* '331 Password required for username\n'
*resp* '331 Password required for username'
*cmd* 'PASS ********'
*put* 'PASS ********\r\n'
*get* '230 User username logged in\n'
*resp* '230 User username logged in'
FTP and SFTP are two completely different protocols. They have absolutely nothing in common. There's no chance you can connect with an FTP library to an SFTP server.
Your log shows FTP session without any doubt.
Though you (or your host) may mistake SFTP with FTPS (FTP over TLS/SSL). See FTPS versus SFTP. For FTPS, just use FTP_TLS
class instead of FTP
. The interface is the same (FTP_TLS
derives from FTP
).
If you really need SFTP (over SSH), you need to use a different library, like Paramiko or pysftp.
See SFTP in Python? (platform independent).