Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SFTP using ftplib

I need to download a file from a host using SFTP.

Do you know if is it possible to do that using Python ftplib? I saw an example here, but when I try to connect I receive EOFError.

I tried this code:

import ftplib
ftp = ftplib.FTP()
ftp.connect( "1.2.3.4", "22" )

This method returns with an error after long time so I cannot perform a call to login. I cannot try the constructor FTP([host[, user[, passwd[, acct[, timeout]]]]]) because my port is 22 but ftplib default is 21.

If I follow the example

ftp = ftplib.FTP("1.2.3.4")
ftp = ftplib.FTP("1.2.3.4","22")

I receive a connection refused so I cannot enter any username password. Can you help me? Thank you very much

like image 704
Abruzzo Forte e Gentile Avatar asked Jan 07 '10 11:01

Abruzzo Forte e Gentile


People also ask

Does Ftplib work with SFTP?

Save this answer. Show activity on this post. As the question you linked to states, ftplib doesn't support SFTP (which is a transfer protocol over SSH and has nothing to do with FTPS, FTP over SSL). Use the recommended Paramiko instead.

Can I use FTP to connect to SFTP server?

In order to make a secure connection to a FTP server, you can use any application that support SFTP. SFTP (commonly referred to as Secure File Transfer Protocol ) can perform secure file transfers. For secure transfers, it uses Secure Shell (SSH) and supports the SCP protocol in addition to SFTP.

Is SFTP same as FTP?

What's the Difference Between FTP vs SFTP, Then? The key difference between FTP vs SFTP is that SFTP uses a secure channel to transfer files while FTP doesn't. With SFTP, your connection is always secured and the data that moves between your FTP client and your web server is encrypted.


1 Answers

As the question you linked to states, ftplib doesn't support SFTP (which is a transfer protocol over SSH and has nothing to do with FTPS, FTP over SSL). Use the recommended Paramiko instead.

like image 129
David Schmitt Avatar answered Sep 21 '22 17:09

David Schmitt