Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import csv
- from ftplib import FTP
- from optparse import OptionParser
- parser = OptionParser()
- parser.set_usage("%prog [options] list_file")
- parser.set_description("script for getting a list of files defined in other file")
- parser.add_option("-s","--server",dest="server",
- help="server from get the files",
- default="")
- parser.add_option("-u","--user",dest="user",
- help="ftp user of server",
- default="")
- parser.add_option("-p","--upassword",dest="password",
- help="ftp password of user",
- default="")
- parser.add_option("-d","--directory",dest="directory",
- help="directory on server where the files are located",
- default="/")
- parser.add_option("-w","--writein",dest="writein",
- help="directory where the files are saved")
- (options, args) = parser.parse_args()
- if len(args) != 1:
- print "the list file option is required"
- print parser.get_usage()
- exit()
- ftp = FTP(options.server, options.user, options.password)
- ftp.cwd(options.directory)
- # leer el archivo de rutinas y traer los archivos por ftp 1 a 1
- reader = csv.reader(open(args[0],"rb"))
- counter=1
- for row in reader:
- print "getting " + str(counter) + " : " + row[0]
- counter += 1
- ftp.retrbinary("RETR " + row[0], open(options.writein + row[0], 'wb').write)
- ftp.quit()
- ftp.close()
Add Comment
Please, Sign In to add comment