I'm trying to create a code to download N files at the same type using pysftp and multiprocessing libs. I made a basic python training, got pieces of codes and combined them into one, but I can't get it work out. I'd appreciate if somebody helps me with that. The error occurs after the vFtp.close() command. In the part that suppose to start simultaneous downloads.
from multiprocessing import Pool
import pysftp
import os
vHost='10.11.12.13'
vLogin='admin'
vPwd='pass1234'
vFtpPath='/export/home/'
os.chdir('d:/test/')
os.getcwd()
cnopts=pysftp.CnOpts()
cnopts.hostkeys = None
vFtp=pysftp.Connection(vHost,username=vLogin,password=vPwd,cnopts=cnopts)
vFtp.cwd(vFtpPath)
vObjectList=vFtp.listdir()
vFileList=[]
vFoldList=[]
for vObject in vObjectList:
vType=str(vFtp.lstat(vObject))[:1]
if vType!='d':
vFileList.append(vObject)
else:
vFoldList.append(vObject)
vFtp.close()
def fDownload(vFileAux):
vFtpAux=pysftp.Connection(vHost,username=vLogin,password=vPwd,cnopts=cnopts)
vFtpAux.cwd(vFtpPath)
vFtpAux.get(vFileAux,preserve_mtime=True)
vFtpAux.close()
if __name__ == "__main__":
vPool=Pool(3)
vPool.map(fDownload,vFileList)