ftp 123.456
Name: anonymous
Password: password
binary
cd 001
get mfile.d.Z
I need to write a script which performs above codes to retrieve data automatically.
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.
Sign up to join this communityftp 123.456
Name: anonymous
Password: password
binary
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:
#!/usr/bin/python
import ftplib
host = '127.0.0.1'
dir = '001'
filename = 'mdfile.d.z'
# connect
ftp = ftplib.FTP(host)
# login - anonymous by default
# use ftp.login("username", "password") if no anon access
ftp.login()
# change to desired dir
ftp.cwd(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)