Advertisement
Guest User

Untitled

a guest
Mar 18th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #! /usr/bin/python
  2.  
  3. import ftplib
  4. import os
  5.  
  6. server = 'servername' #credentials
  7. username = 'username'
  8. password = 'password'
  9. myFTP = ftplib.FTP(server, username, password) #create connection
  10. myPath = r'folder_to_directory' #path to folder to be uploated
  11. def uploadMe(path):
  12. files = os.listdir(path) #list files(directories or binaries) to determine loop
  13. os.chdir(path) #change directory
  14. for f in files:
  15. if os.path.isfile(f): #if is file
  16. imyFTP.storbinary('STOR %s' %f, open(f, 'rb')) #open and upload
  17. elif os.path.isdir(f): #if is directory
  18. myFTP.mkd(f) #create directory
  19. myFTP.cwd(f) #go to the created directory
  20. uploadMe(path + '/' + f) #recursive run
  21. myFTP.cwd('..')
  22. os.chdir('..')
  23. uploadMe(myPath) #run
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement