sftp using ftplib

こ雲淡風輕ζ 提交于 2019-12-01 15:22:11

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/2019780/sftp-using-ftplib

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!