def main():
    if test:
        cred = getCredentials("C:/PythonScripts/dependencies/FTP/FC-Credentials.txt")
        successLog = log("C:/PythonScripts/dependencies/FTP/GoldmanHourlyLastUpload_test.txt")
    else:
        cred = getCredentials(credentialsFilePath)        
        successLog =log(statuslogPath)

    ## iterate over every FTP url from the credentials File
    for url in cred.keys():
        try:
            conn = ftplib.FTP(url.strip())

            #Use ACTV mode if neccessary
            if url in actvURLs:
                conn.set_pasv(False)

            conn.login(cred[url][0], cred[url][1])
            conn.cwd('incoming')
        except Exception, e:
            getput.logger(getput.logFileName, e.message + ' username: '******', password: '******'filecheck ',  filecheck
        
        while(int(filecheck[-16:-4]) >= int(f[-16:-4])):
            #print f
            
            try:
                print 'madeit'
                getput.logger(getput.logFileName,"trying to open " + f + " from " + FCFtpServer)   
                #print 'truth ', getput.put(conn, f, open(FCFtpServer+ f))
                if(getput.put(conn, f, open(FCFtpServer+ f))):
                    print 'success'
                    ## only write to the log file if the upload was successful
                    successLog.overWriteForCompany(url, "last upload: " + f)
                elif(open(FCFtpServer+ str(int(f[15:-4]) + 100))):
                    print 'tried to open'
                    getput.put(conn, f, open(FCFtpServer+ str(int(f[15:-4]) + 100)))
                else:
                    print 'failed'
                    getput.logger(getput.logFileName,"unable to upload file to client @ " + time.localtime().tm_hour + ":" \
                                      + time.localtime().tm_min)               
            except IOError, e:
                ## catch the inevitable IOError when looking for unpublished file (next hour's file)
                print 'exception'
                getput.logger(getput.logFileName,"remote file " + f +  \
                              " was not found. Re-attempt after file is published to FirstCoverage ftp server")
            
            f = filename % getNextDateStamp(f[-16:-4])
Exemple #2
0
def main():
    cred = getCredentials(credentialsFilePath)        
    successLog = log(statuslogPath)
    successLog.setLogFile("C:\PythonScripts\dependencies\FTP\lastUpload.txt")

    ## iterate over every FTP url from the credentials File
    for username in cred.keys():
        try:
            url = cred[username][2]
            conn = ftplib.FTP(url.strip())

            #Use ACTV mode if neccessary
            if url in actvURLs:
                conn.set_pasv(False)

            conn.login(cred[username][0], cred[username][1])
        except Exception, e:
            getput.logger("C:\pythonscripts\dependencies\ftp\sac_log.txt", e.message + ' username: '******', password: '******'eod_Europe', username.upper())
                #open(usernamePath[username]+ f)
                print 'madeit'
                print usernamePath[username]+ f
                returnMessage = getput.put(conn, sendName, open(usernamePath[username]+ f), True)
                if('226' in returnMessage[1]):
                    print 'success'
                    ## only write to the log file if the upload was successful
                    successLog.overWriteForCompany(username, "last upload: " + f)    
                else:
                    print 'failed'
                    getput.logger("C:\pythonscripts\dependencies\ftp\sac_log.txt","unable to upload file to client @ " + str(time.localtime().tm_hour) + ":" \
                                      + str(time.localtime().tm_min))               
            except IOError, e:
                ## catch the inevitable IOError when looking for unpublished file (next hour's file)
                print '!!!!EXCEPTION!!!!'
                ##print "remote file " + f +  \
                ##              " was not found. Re-attempt after file is published to FirstCoverage ftp server"
                getput.logger("C:\pythonscripts\dependencies\ftp\sac_log.txt","remote file " + f +  \
                              " was not found. Re-attempt after file is published to FirstCoverage ftp server")
                
            f = filename % getNextDateStamp(f[:8], False)
def main():
    cred = getCredentials(credentialsFilePath)        
    successLog =logWithUser(statuslogPath)
    pullFromPushTo = getPushAndPullInfo(fromToInfo)
    frequency = getPushFrequency(frequencyInfo)

    ## iterate over every FTP url from the credentials File
    for url in cred.keys():
        #for user in frequency:
        #    if frequency[user][1] == 'hourly':
        #        ##continue to connection
        #    elif frequency[user][1] == 'daily' and time.localtime().tm_hour > frequency[user][0][:-3]:
        print url
        for usr, dir, filename in pullFromPushTo[url]:            
            print usr, dir, filename

                
            try:
                conn = ftplib.FTP(url.strip())

                #Use ACTV mode if neccessary
                if url in actvURLs:
                    conn.set_pasv(False)

                conn.login(cred[url][0], cred[url][1])
            
            except Exception, e:
#                getput.logger(
                print getput.logFileName + e.message + ' username: '******', password: '******'daily':
                print 'got here?'
                print checkLogForStatus(url, successLog.getLogFileName(), False)
                stamp = getNextDateStamp(checkLogForStatus(url, successLog.getLogFileName(), False), False)
                print stamp
                print stamp[:-4]
                f = filename % stamp
                print f
            else:
                f =  filename % getNextDateStamp(checkLogForStatus(url, successLog.getLogFileName()))
            
            ##filecheck is a filename based on the CURRENT time        
            filecheck = filename % getNextDateStamp(None)
            print filecheck

            print "frequency loop : ", frequency[usr][1]
            if frequency[usr][1] == 'hourly':
                while(int(filecheck[-16:-4]) >= int(f[-16:-4])):
                    print f
                
                    try:
                        print 'madeit 1'
                        getput.logger(getput.logFileName,"trying to open " + f + " from " + dir)   
                        
                        if(getput.put(conn, f, open(dir+ f))):
                            print 'success'
                            ## only write to the log file if the upload was successful
                            successLog.overWriteForCompany(url, "last upload: " + f, usr)
                        elif(open(dir+ str(int(f) + 100))):
                            print 'tried to open'
                            getput.put(conn, f, open(dir+ str(int(f) + 100)))
                        else:
                            print 'failed'
                            getput.logger(getput.logFileName,"unable to upload file to client @ " + time.localtime().tm_hour + ":" \
                                          + time.localtime().tm_min)               
                    except IOError, e:
                        ## catch the inevitable IOError when looking for unpublished file (next hour's file)
                        print 'exception'
                        #getput.logger(
                        print   " remote file " + f +  \
                                  " was not found. Re-attempt after file is published to FirstCoverage ftp server"
                
                    f = filename % getNextDateStamp(f[-16:-4])
            
            else:
                try:
                    print 'madeit 2'
#                   getput.logger(getput.logFileName,
                    print "trying to open " + f + " from " + dir
                    pushable = open(dir+ f)
                        
                    if(getput.put(conn, f, pushable)):
                        print 'success'
                        ## only write to the log file if the upload was successful
                        successLog.overWriteForCompany(url, "last upload: " + f)
                    #elif(open(dir+ str(int(f) + 1))):
                    #    print 'tried to open'
                    #    getput.put(conn, f, pushable)
                    else:
                        print 'failed'
                        getput.logger(getput.logFileName, "unable to upload file to client @ " + str(time.localtime().tm_hour) + ":" \
                                  + str(time.localtime().tm_min))
                except IOError, e:
                    ## catch the inevitable IOError when looking for unpublished file (next hour's file)
                    print 'exception'
                    #getput.logger(
                    print "message", e.message
                    print getput.logFileName + " remote file " + f +  \
                              " was not found. Re-attempt after file is published to FirstCoverage ftp server"