ftp 123.456
Name: anonymous
Password: password
cd 001
get mfile.d.Z

I need to write a script which performs above codes to retrieve data automatically.


Here's a simple Python script:


import ftplib

host = ''
dir = '001'
filename = 'mdfile.d.z'

# connect

ftp = ftplib.FTP(host)

# login - anonymous by default
# use ftp.login("username", "password") if no anon access


# change to desired dir


# fetch the file, and copy it to a file of the
# same name in the local pwd

with open(filename, 'wb') as local_file:
    ftp.retrbinary("RETR {}".format(filename), local_file.write) 
  • I tried but it didn't work – deepblue_86 Jun 8 '15 at 19:52
  • Can you elaborate? "didn't work" is a pretty broad statement. – stevieb Jun 8 '15 at 19:54
  • my OS just freeze when I execute the script. Here the other way I tried, host='123.456' Name='anonymous' passw:'123456' ftp $host , from here everything is ok but I don't know how I can write Name within script – deepblue_86 Jun 8 '15 at 20:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.