Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/python
- import ftplib
- import os
- server = 'servername' #credentials
- username = 'username'
- password = 'password'
- myFTP = ftplib.FTP(server, username, password) #create connection
- myPath = r'folder_to_directory' #path to folder to be uploated
- def uploadMe(path):
- files = os.listdir(path) #list files(directories or binaries) to determine loop
- os.chdir(path) #change directory
- for f in files:
- if os.path.isfile(f): #if is file
- imyFTP.storbinary('STOR %s' %f, open(f, 'rb')) #open and upload
- elif os.path.isdir(f): #if is directory
- myFTP.mkd(f) #create directory
- myFTP.cwd(f) #go to the created directory
- uploadMe(path + '/' + f) #recursive run
- myFTP.cwd('..')
- os.chdir('..')
- uploadMe(myPath) #run
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement