frameworker frameworker -4 years ago 116
Python Question

ftplib connects to sftp server without error

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 (wich is important for this application). Especially as I could not find similar cases online. Wich brings me to the followng questions:


  1. How can I find out if the connection is encrypted? (current status: It's not encrypted)

  2. If the connection is not encrypted: How can I support sftp without having to recode my complete library?



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'

Answer Source

FTP and SFTP are two completely different protocols. They have absolutely nothing in common. There's no chance you can connect with FTP library to SFTP server.

Your log is shows FTP protocol without any doubt.

Though you (our your host) may mistake SFTP with FTPS (FTP over TLS/SSL). For FTPS, just use FTP_TLS instead of FTP. The interface is the same (FTP_TLS derives from FTP).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download