【问题标题】:Getting EOFError while connecting to FTP server on port 22 with Python ftplib使用 Python ftplib 在端口 22 上连接到 FTP 服务器时出现 EOFError
【发布时间】:2021-10-22 03:31:56
【问题描述】:

我正在编写简单的 Python 程序来将 CSV 上传到 FTP 服务器。当我使用 WinSCP 连接时,我能够连接到 FTP 服务器。但是当我运行我的 Python 程序时,它以以下错误结束。

  ftp.connect(host, 22)
  File "C:\Python\Python39\lib\ftplib.py", line 162, in connect
    self.welcome = self.getresp()
  File "C:\Python\Python39\lib\ftplib.py", line 244, in getresp
    resp = self.getmultiline()
  File "C:\Python\Python39\lib\ftplib.py", line 234, in getmultiline
    nextline = self.getline()
  File "C:\Python\Python39\lib\ftplib.py", line 218, in getline
    raise EOFError
EOFError
host = "sftp.xx.com"
username = "username"
password = "passwrd"

ftp = FTP()
ftp.connect(host, 22)
print("..")
login_status = ftp.login(username,password)
print(login_status)
# change directory to upload
ftp.cwd('/content/remotedir')
# print the content of directory
print(ftp.dir())
fp = open("C:\sample.csv", 'rb')
# upload file
ftp.storbinary('STOR %s' % os.path.basename("C:\sample.csv"), fp, 1024)
fp.close()

print(ftp.dir())

【问题讨论】:

    标签: python ftp ftplib


    【解决方案1】:

    ftplib 是一个 FTP 客户端。端口 22 用于 SFTP。那是完全不同的协议。

    对于 Python 中的 SFTP,请使用 Paramiko 或 pysftp。

    【讨论】:

    • 我是python的新手。现在安装的Paramiko解决了错误。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-12
    • 2012-08-23
    • 1970-01-01
    相关资源
    最近更新 更多