Advertisement
Guest User

Python3 - upload all files in folder (FTP)

a guest
Jan 26th, 2019
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. import time
  2. import sys
  3.  
  4. #put this file in your /bin/THISFILE
  5. #upload files only python3
  6. print("mycloud v0.1")
  7.  
  8. time.sleep(1)
  9.  
  10. if len(sys.argv) == 4:
  11. FILENAME = []
  12.  
  13. HOST = str(sys.argv[1])
  14. USER = str(sys.argv[2])
  15. PASS = str(sys.argv[3])
  16.  
  17. ftp = FTP(HOST)
  18.  
  19. if ftp:
  20. print(ftp)
  21. else:
  22. print("ERROR: Could not connect to {}".format(HOST))
  23. sys.exit(1)
  24. login = ftp.login(user=USER, passwd=PASS)
  25.  
  26. if login:
  27. print(login)
  28. else:
  29. print("ERROR: Could not Login to FTP Server!")
  30. sys.exit(1)
  31. else:
  32. print("ERROR: FILE <ip> <username> <password>")
  33. sys.exit(1)
  34. def upload_file(FILENAME):
  35. for f in os.listdir(os.curdir):
  36. if os.path.isfile(f):
  37. FILENAME.append(f)
  38.  
  39. for get_names in FILENAME:
  40. UPLOAD_FILE = ftp.storbinary('STOR ' + get_names, open(get_names, 'rb'))
  41.  
  42. if UPLOAD_FILE:
  43. print("sucsessfully uploaded {} - {}".format(get_names,UPLOAD_FILE))
  44. else:
  45. print("ERROR: Could not upload {} - {}".format(get_names,UPLOAD_FILE))
  46.  
  47.  
  48. ftp.quit()
  49.  
  50. upload_file(FILENAME)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement