简体   繁体   English

如何使用 Python 中的 Paramiko 连接到公共 FTP 服务器?

[英]How to connect to a public FTP server using Paramiko in Python?

I am trying to connect to a public FTP server using Paramiko.我正在尝试使用 Paramiko 连接到公共 FTP 服务器。 Since the FTP server is public it don't have username and password.由于 FTP 服务器是公开的,它没有用户名和密码。 So I run following commands:所以我运行以下命令:

client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
trans = paramiko.Transport(("ftp.***.com", 22))
trans.connect()

But I am getting error in executing the last command.但是我在执行最后一个命令时出错。

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/userstar713/workspace/work/serverless/python/ftp-s3-sls/venv/lib/python3.6/site-packages/paramiko/transport.py", line 1291, in connect
    self.start_client()
  File "/home/userstar713/workspace/work/serverless/python/ftp-s3-sls/venv/lib/python3.6/site-packages/paramiko/transport.py", line 660, in start_client
    raise e
  File "/home/userstar713/workspace/work/serverless/python/ftp-s3-sls/venv/lib/python3.6/site-packages/paramiko/transport.py", line 2039, in run
    self._check_banner()
  File "/home/userstar713/workspace/work/serverless/python/ftp-s3-sls/venv/lib/python3.6/site-packages/paramiko/transport.py", line 2216, in _check_banner
    "Error reading SSH protocol banner" + str(e)
paramiko.ssh_exception.SSHException: Error reading SSH protocol banner

Please give me suggestion.请给我建议。 Thanks谢谢

Paramiko is an SFTP library, not FTP library. Paramiko 是一个 SFTP 库,而不是 FTP 库。 SFTP servers that do not require any credentials are almost non-existent.不需要任何凭据的 SFTP 服务器几乎不存在。 And even the error message you are getting suggests that you are not connecting to an SFTP server.甚至您收到的错误消息也表明您没有连接到 SFTP 服务器。

If it is indeed an FTP server, you need to use an FTP library, like ftplib .如果确实是 FTP 服务器,则需要使用 FTP 库,例如ftplib

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM