[英]Getting EOFError while connecting to FTP server on port 22 with Python ftplib
I am writing simple Python program to upload CSV to FTP server.我正在编写简单的 Python 程序,将 CSV 上传到 FTP 服务器。 I am able to connect to the FTP server when I connect using WinSCP.
当我使用 WinSCP 连接时,我能够连接到 FTP 服务器。 But when I run my Python program, it ends with the below error.
但是当我运行我的 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())
The ftplib is an FTP client. ftplib 是一个 FTP 客户端。 The port 22 is for SFTP.
端口 22 用于 SFTP。 That's a completely different protocol.
那是一个完全不同的协议。
For SFTP in Python, use Paramiko or pysftp.对于 Python 中的 SFTP,请使用 Paramiko 或 pysftp。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.