Python 无法将文件上载到FTP
我一直在尝试在AWS EC2实例中将文件上载到FTP。我已经为相同的用户创建了根用户。我收到一个操作超时错误。下面是我的代码:Python 无法将文件上载到FTP,python,amazon-web-services,ftplib,Python,Amazon Web Services,Ftplib,我一直在尝试在AWS EC2实例中将文件上载到FTP。我已经为相同的用户创建了根用户。我收到一个操作超时错误。下面是我的代码: ftp = ftplib.FTP() host = "ec2-my-ip.compute-1.amazonaws.com" port = 21 username = 'username' password = 'password' ftp.connect(host, port) print (ftp.getwelc
ftp = ftplib.FTP()
host = "ec2-my-ip.compute-1.amazonaws.com"
port = 21
username = 'username'
password = 'password'
ftp.connect(host, port)
print (ftp.getwelcome())
ftp.login(username, password)
print 'logged in'
ftp.cwd("/home/user/")
print 'changed directory'
ftp.retrbinary('RETR abc.png', open('/Users/Subhrajyoti/Downloads/abc.png', 'wb').write)
print 'file transferred'
ftp.quit()
下面是我得到的输出:
220 (vsFTPd 2.3.5)
abc
changed directory
[Errno 60] Operation timed out
使用filezilla进行连接时,出现以下错误:
Status: Resolving address of ec2-my_ip.compute-1.amazonaws.com
Status: Connecting to my_ip:21...
Status: Connection established, waiting for welcome message...
Status: Insecure server, it does not support FTP over TLS.
Status: Logged in
Status: Retrieving directory listing...
Command: PWD
Response: 257 "/home/user"
Command: TYPE I
Response: 200 Switching to Binary mode.
Command: PASV
Response: 227 Entering Passive Mode (my,machine,ip,25,4,1).
Command: LIST
Error: Connection timed out after 20 seconds of inactivity
Error: Failed to retrieve directory listing
我已经按照python中提供的说明进行了操作。
我做错了什么?Retr是下载文件的命令。你想上传,对吗?是的,我想上传。我见过使用RETR的例子。再次,如果我尝试
ftp.retrlines('LIST')
,那么我也会得到操作超时错误。理想情况下,此操作应列出文件夹中的所有文件。您可以根据此处的文档,使用“FTP.storbinary”进行检查。在此之前,我建议您尝试使用命令行ftp客户端或基于gui的客户端(如FileZilla)上载文件,以确保aws权限设置为允许上载。我尝试使用FileZilla并在其中获得了erorr。更新了我的问题中的相同内容。我还是不明白。也许FTPLIB不是亚马逊的发展方向。显然,Amazon有某种python sdk。退房