0

I have been trying to upload a file to FTP in a AWS EC2 instance. I have created a ROOT user for the same. I am getting an Operation timed out error. Below is my code:

    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()

Below is the output that i am getting:

    220 (vsFTPd 2.3.5)
    abc
    changed directory
    [Errno 60] Operation timed out

When i am using filezilla to connect i am getting the following error:

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

I have followed the instructions provided in the python FTPLIB. What am i doing wrong?

Subhrajyoti Das
  • 2,685
  • 3
  • 21
  • 36
  • Retr is a command to download a file. You want to upload, Right? – sevzas Apr 11 '17 at 11:47
  • Yes i want to upload. I had seen examples which use RETR. Again if i try `ftp.retrlines('LIST')` then also i get the operation timed out error. Ideally this operation should List down all the files in the folder. You can check this [link](http://stackoverflow.com/questions/11573817/how-to-download-a-file-via-ftp-with-python-ftplib) – Subhrajyoti Das Apr 11 '17 at 11:50
  • try using "FTP.storbinary" based on the docs here https://docs.python.org/2/library/ftplib.html . Before you do that, I suggest you try uploading a file with the command-line ftp client or a gui-based client such as FileZilla just to make sure that the aws permissions are set up to allow it. – sevzas Apr 11 '17 at 12:00
  • I tried using FileZilla and got erorr in it. Updated the same in my question. Cant figure out still. – Subhrajyoti Das Apr 11 '17 at 12:22
  • Perhaps FTPLIB is not the way to go for amazon. Apparently Amazon has a python sdk of some sort. Check out http://stackoverflow.com/questions/15085864/how-to-upload-a-file-to-directory-in-s3-bucket-using-boto – sevzas Apr 11 '17 at 12:33

0 Answers0