Python FTP Upload with Multiprocessing - Uploaded Files not complete
Question: i was trying to create a ftp upload with multiprocessing like it is described
here in many different ways. The skript already uploads the files I choose but
the upload breaks up every time after uploading round about 90 KB. Does
anybody has a hint for me what I did wrong ? Thanks in advance. Regards Peter

    
    
    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    import ftplib
    from ftplib import FTP
    from multiprocessing import Process
    import os
    
    
    ##### Config für den Upload Path ####
    Path='c:/'
    #####################################
    
    def uploadZip(zipName,PathUpload):
        # Hochzuladenden XML
        # Upload zu Datenausstausch - Test
        ftpsportschau= FTP('xxxxx')
        ftpsportschau.login ('xxx', 'xxxx')
        zipDatei = open('%s%s' %(PathUpload,zipName),'r')
        try:
           ftpsportschau.storbinary('STOR %s' % zipName, zipDatei)
    
        except ftplib.error_perm:
           print "PermError: cannot upload file %s" % zipName
    
        except ftplib.error_temp:
           print "TempError: cannot upload file %s" % zipName
    
        zipDatei.close()
        ftpsportschau.quit()
        return 
    
    def UploadAsync(FileListe,PathAsync):
        ''' Funktion zum Upload mit parallelen Prozessen
            Sie enthält nicht den Upload Befehl,sondern nur den Aufruf der Prozesse
        '''
        print ' List in Async'+'\n'
        print FileListe
    
        try:
            for filename in FileListe:
                p = Process(target=uploadZip, args=(filename,PathAsync))
                p.start()
    
        except:
            print 'An error has occured'
    
    def Files(PathFiles):
        ''' Funktion zum Ermitteln der Files'''
        UploadListe=[]
        Files=os.listdir(PathFiles)
        print Files
        print '\n'
        for files in Files:
            if files.endswith('.zip'):
                UploadListe.append(files)
            else: continue
        print UploadListe
        print '\n'
        return UploadListe
    
    if __name__ == "__main__":
        UploadAsync(Files(Path),Path)
    


Answer: Since you seem to be transferring filesin binary format, you should use the
`'b'` qualifier in your open:

    
    
    zipDatei = open('%s%s' %(PathUpload,zipName),'rb')
    

