Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- from __future__ import print_function
- from subprocess import call
- import os, sys, ftplib, string, traceback, datetime
- logtime = datetime.datetime.now()
- logtimeString = logtime.strftime("%Y-%m-%d_%H:%M:%S")
- successLogs = "successLogs." + logtimeString + ".txt"
- failureLogs = "failureLogs" + logtimeString + ".txt"
- successLogFile = open(successLogs, 'a')
- failureLogFile = open(failureLogs, 'a')
- #successLogFile.write("success, error is: " + e + ", continuing\n")
- #failureLogFile.write("failed, error is: " + e + "\n")
- def printFileError(fileError):
- print("something went bad with file", fileError, file=failureLogFile)
- def processVMX(vmxPath):
- vmxTmpPath = vmxPath + ".bak"
- os.rename(vmxPath, vmxTmpPath)
- #print("before open vmx")
- vmxFile = open(vmxPath, 'w')
- vmxOldFile = open(vmxTmpPath, 'r')
- #print("opened..")
- for line in vmxOldFile.readlines():
- # print("for line")
- # if "virtualHW.version = \"8\"" in line:
- # print("in if statement")
- vmxFile.write(line.replace('virtualHW.version = "8"', 'virtualHW.version = "7"'))
- # vmxFile.write(line)
- # print("wrote to file")
- #o.write(line + "\n")
- vmxFile.close()
- vmxOldFile.close()
- os.remove(vmxTmpPath)
- def uploadToFTP(path,user,pwd):
- #print "before ftplib.."
- ftp = ftplib.FTP()
- host = "ftp.cloud.skytap.com"
- port = 21
- #print "before connecting.."
- ftp.connect(host,port)
- #print "connected, before getwelcome"
- #print(ftp.getwelcome())
- #print "got welcome"
- #print("connecting....")
- try:
- try:
- ftp.login(user,pwd)
- ftp.cwd("/upload")
- #print "Currently in:", ftp.pwd() # double check make sure this says /upload
- #print "finished logging in..."
- for root, dirs, files in os.walk(path, onerror=printFileError):
- #for root, dirs, files in os.walk(path):
- checker = os.system('md5sum -c md5sum.txt') #might need to modify
- if(0 == checker):
- for f in files:
- fullPath = os.path.abspath(root + '/' + f)
- #os.system('md5 ' + fullPath + ' > ' + fullPath + '.md5') #might need to modify
- if(fullPath.endswith(".vmx")):
- processVMX(fullPath)
- #print "Uploading:", fullPath
- fileToUpload = open(fullPath, "rb")
- ftp.storbinary('STOR ' + f, fileToUpload)
- fileToUpload.close()
- #MD5checker fileToUpload = open(fullPath + '.md5', "rb")
- #MD5checker ftp.storbinary('STOR <ftp://ftp.storbinary('STOR> ' + f + '.md5', fileToUpload)
- #MD5checker fileToUpload.close()
- print("Uploaded file", fullPath, file=successLogFile)
- finally:
- ftp.quit()
- except e:
- print("something went wrong:", e, fileName=errorLogFile)
- #raw_input("Press enter...")
- configFile = open(sys.argv[1], 'r')
- for line in configFile:
- info = string.split(line, ':')
- uploadToFTP(info[0], info[1], info[2])
- configFile.close()
- successLogFile.close()
- failureLogFile.close()
Add Comment
Please, Sign In to add comment