Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Upload Tectonicus changed.txt files to ftp host.
- # By LordMike91
- # V 0.5
- # imports
- import os, sys
- from ftplib import FTP
- from sets import Set
- print "imports loaded"
- # Vars
- changeFile = 'x:\\tectonicus\\changed.txt'
- localRoot = 'x:\\tectonicus\\'
- remoteRoot = '/'
- remoteHost = '127.0.0.1'
- remoteUser = ''
- remotePass = ''
- # Make a list of changed files
- fChanged = open(changeFile, 'r')
- files = []
- for line in fChanged:
- # Tuple: localPath, remotePath
- t = line.strip(), line.replace(localRoot, '').strip().replace('\\', '/')
- files.append(t)
- #print line
- print "BLAH"
- fChanged.close()
- # Connect to FTP
- ftp = FTP(remoteHost, remoteUser, remotePass)
- ftp.cwd(remoteRoot)
- # Upload files
- i = 0
- createdDirectories = Set()
- print "FOR LOOP HAPPENING"
- for f in files:
- i += 1
- print i
- print "----"
- # Make directory
- folders = f[1].split('/')
- for v in range(0, len(folders)):
- # Prepend previous folders
- folder = ''
- for p in range(0, v):
- folder += folders[p] + '/'
- if folder not in createdDirectories:
- # Folder has not been attempted created before
- # Saves a lot of unecessary work
- try:
- ftp.mkd(folder)
- # print 'Made folder ' + folder
- except:
- pass
- createdDirectories.add(folder)
- print "Uploading file " + str(i) + " / " + str(len(files)) + " (" + str(f[1]) + ")"
- while True:
- try:
- toUpload = open(f[0], 'rb')
- ftp.storbinary('STOR ' + f[1], toUpload)
- toUpload.close()
- break
- except:
- # Error uploading
- print 'Error uploading - trying again'
- # Close connection
- ftp.quit()
Add Comment
Please, Sign In to add comment