使用多处理的Python FTP上传 - 上传的文件未完成

时间:2014-02-06 11:02:55

标签: python file-upload ftp multiprocessing

我正在尝试使用多处理创建一个ftp上传,就像这里以许多不同的方式描述的那样。 skript已经上传了我选择的文件,但每次上传大约90 KB后上传就会中断。有没有人暗示我做错了什么? 提前致谢。 关心彼得

#!/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)

1 个答案:

答案 0 :(得分:0)

由于您似乎是以二进制格式传输文件,因此您应该在开放时使用'b'限定符:

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