Guest User

Untitled

a guest
Feb 19th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import csv
  4. from ftplib import FTP
  5. from optparse import OptionParser
  6.  
  7. parser = OptionParser()
  8. parser.set_usage("%prog [options] list_file")
  9. parser.set_description("script for getting a list of files defined in other file")
  10. parser.add_option("-s","--server",dest="server",
  11. help="server from get the files",
  12. default="")
  13. parser.add_option("-u","--user",dest="user",
  14. help="ftp user of server",
  15. default="")
  16. parser.add_option("-p","--upassword",dest="password",
  17. help="ftp password of user",
  18. default="")
  19. parser.add_option("-d","--directory",dest="directory",
  20. help="directory on server where the files are located",
  21. default="/")
  22. parser.add_option("-w","--writein",dest="writein",
  23. help="directory where the files are saved")
  24. (options, args) = parser.parse_args()
  25. if len(args) != 1:
  26. print "the list file option is required"
  27. print parser.get_usage()
  28. exit()
  29.  
  30. ftp = FTP(options.server, options.user, options.password)
  31. ftp.cwd(options.directory)
  32. # leer el archivo de rutinas y traer los archivos por ftp 1 a 1
  33. reader = csv.reader(open(args[0],"rb"))
  34. counter=1
  35. for row in reader:
  36. print "getting " + str(counter) + " : " + row[0]
  37. counter += 1
  38. ftp.retrbinary("RETR " + row[0], open(options.writein + row[0], 'wb').write)
  39. ftp.quit()
  40. ftp.close()
Add Comment
Please, Sign In to add comment