반응형
FTP 서버에 쉽게 연결하고 zip 파일을 여는 다음 코드가 있습니다. 해당 파일을 로컬 시스템에 다운로드하고 싶습니다. 그렇게하는 방법?
# Open the file for writing in binary mode
print 'Opening local file ' + filename
file = open(filename, 'wb')
# Download the file a chunk at a time
# Each chunk is sent to handleDownload
# We append the chunk to the file and then print a '.' for progress
# RETR is an FTP command
print 'Getting ' + filename
ftp.retrbinary('RETR ' + filename, handleDownload)
# Clean up time
print 'Closing file ' + filename
file.close()
해결 방법
handle = open(path.rstrip("/") + "/" + filename.lstrip("/"), 'wb')
ftp.retrbinary('RETR %s' % filename, handle.write)
참조 페이지 https://stackoverflow.com/questions/11573817
반응형
'파이썬' 카테고리의 다른 글
파이썬 Python 코드의 메서드에서 현재 호출 스택 인쇄 (0) | 2021.02.12 |
---|---|
파이썬 목록에서 모든 값을 제거 하시겠습니까? (0) | 2021.02.12 |
파이썬 로거별로 Python 로그 메시지의 형식을 변경하려면 어떻게해야합니까? (0) | 2021.02.12 |
파이썬 numpy 배열이 참조로 전달됩니까? (0) | 2021.02.12 |
파이썬의 다변량 정규 밀도? (0) | 2021.02.12 |
댓글