使用ftplib和多处理上传多个文件

时间:2015-05-03 07:19:31

标签: python multithreading python-2.7 multiprocessing

我正在使用ftp尝试多个文件。但是,它不是上传多个不同的文件,而是多次上传一个文件。怎么了?

import fnmatch
import os
from multiprocessing import Pool
import ftplib

file_extensions = [ '*.mp4', '*wmv' ]
matches = []
#match = []
exclude = "/ext_hdd/download/incomplete"
def upload(file):
    ftp = ftplib.FTP('ftp.domain.com')
    ftp.login("username","password")
    f = open(match,'rb')
    print ("uploading" + match)
    ftp.storbinary('STOR %s' %match, f)
    f.close()
    ftp.quit()

for root, dirs, filenames in os.walk("/ext_hdd/download"):
        dirs[:] = [d for d in dirs if d not in exclude]
        for extension in file_extensions:
          for filename in fnmatch.filter(filenames, extension):
                  matches.append(os.path.join(root, filename))
                  (match for match in matches if file_size > 209715200)
                  #print matches
                  for match in matches:
                        pool = Pool(2)
                    pool.map(upload,match)

0 个答案:

没有答案