2015-01-10 2 views
1

ftp 서버에서 파일을 다운로드하고 장고에 데이터를 가져 오려고합니다. 그래서 서버 주소, 로그인 세부 정보, 경로, 파일 이름 및 다운로드 할 파일이있는 위치를 포함하는 목록을 작성하여 다운로드하는 기능에 전달합니다.파이썬 FTP가 방향 오류가 아닙니다

같은 오류를 보여주는 클라이언트 서버로 이동할 때 내 시스템이 재부에서 파일 작업 "오류 C_VAR1_31012014_1.DAT 다운로드 - 아니 디렉토리 [errno를 20] : '일반/VARRate이/C_VAR1_31012014_1.DAT"

이 목록 기능

다음 함수에 전달합니다

self.fileDetails = { 'NSE FO VAR RATE FILE': ('ftp.xxx.com', username, passwd, 'common/VARRate', 'C_VAR1_\d{4}201[45]_\d{1}.DAT', 'Data/samba/Ftp/Capex10/NSECM/VAR RATE'), }

for fileType in self.fileDetails: 
     self.ftpDownloadFiles(fileType) 

이 세부 사항과 같이하는 방법입니다 948,

다운로드 프로세스가 하나라도 대신에() os.path.join 사용하여이 문제를

+0

를 참조? – thefourtheye

+0

내 시스템에서이 코드를 실행할 때 파일이 제대로 다운로드되고 있지만이 코드를 내 클라이언트 시스템으로 옮기면 오류가 표시됩니다. "C_VAR1_31012014_1.DAT를 다운로드하는 중 오류가 발생했습니다 - [Errno 20] 디렉토리가 아닙니다 : 'common/VARRate/C_VAR1_31012014_1 .DAT ". 당신은 내가 로그를 사용하여 오류를 recornding 오전 볼 수 있습니다 – Krish

+1

거기에 로그가 저장되고 있기 때문에 Erorr은 def walkTree 함수에서 일어나는 것입니다 – Krish

답변

2

시도를 해결하는 데 도움이 수

def walkTree(self, ftpclient, remotepath, fileType): 
    # process files inside remotepath; cwd already done 
    # remotepath to be created if it doesnt exist locally 
    copied=matched=downloaded=imported = 0 
    files = ftpclient.nlst() 

    localpath = self.fileDetails[fileType][FDTL_DSTPATH_POS] 
    rexpCompiled = re.compile(self.fileDetails[fileType][FDTL_PATRN_POS]) 

    for eachFile in files: 
     try: 
      ftpclient.cwd(remotepath+'/'+eachFile) 
      self.walkTree(ftpclient, remotepath+'/'+eachFile+'/', fileType) 
     except ftplib.error_perm: # not a folder, process the file 
      # every file to be saved in same local folder as on ftp srv 
      saveFolder = remotepath 
      saveTo = remotepath + '/' + eachFile 
      if not os.path.exists(saveFolder): 
       try: 
        os.makedirs(saveFolder) 
        print "directory created" 
       except BaseException as e: 
        logging.info('\tcreating %s : %s' % (saveFolder, e.__str__())) 
      if (not os.path.exists(saveTo)): 
       try: 
        ftpclient.retrbinary('RETR ' + eachFile, open(saveTo, 'wb').write) 
        #logging.info('\tdownloaded ' + saveTo) 
        downloaded += 1 
       except BaseException as e: 
        logging.info('\terror downloading %s - %s' % (eachFile, e.__str__())) 
       except ftplib.error_perm: 
        logging.info('\terror downloading %s - %s' % (eachFile, ftplib.error_perm)) 
      elif (fileType == 'NSE CASH CLOSING FILE'): # spl case if file exists 
       try: 
        # rename file 
        yr = int(time.strftime('%Y')) - 1 
        os.rename(saveTo, saveTo + str(yr)) 
        # download it 
        ftpclient.retrbinary('RETR ' + eachFile, open(saveTo, 'wb').write) 
        downloaded += 1 
       except BaseException as e: 
        logging.info('\terror rename/ download %s - %s' % (eachFile, e.__str__())) 

시작은 여기에 다음 함수를 호출합니다 여기에서 os가 다운로드 할 경로 구분자로 하드 코드 된 슬래시./또는 \는 로컬 OS에 따라 다릅니다.

코드에서 :

saveTo = remotepath + '/' + eachFile 

이 될 것입니다 :

saveTo = os.path.join(remotepath,eachFile) 

당신이 직면하고있는 실제 문제가 무엇입니까 https://docs.python.org/2/library/os.path.html

+0

언급 한 내용을 수행했지만 여전히 동일한 내용을 보여줍니다 @ michel.iamit – Krish

+0

질문에서 의견보기 및 왜 문제를 해결하지 못했다면 대답으로 받아 들일 수 있습니까? 나는 정보를 놓친다 : 차이점은 무엇인가 : 어떤 운영체제가 작동하고 어느 것이 작동하지 않는가? 권리 일 수 있니? 프로세스에 폴더에 대한 권한이 있습니까? (지역 개발 시스템에서는 일반적으로 모든 권리를 보유하고 있습니다. –

관련 문제