Created
September 13, 2018 04:40
-
-
Save shakyaabiral/699feef6bd0b3457714f6c0f219e55bc to your computer and use it in GitHub Desktop.
Python Download file from ftp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ftplib import FTP | |
import os | |
with FTP('FTP_HOSTNAME') as ftp: | |
ftp.login('FTP_USERNAME', 'FTP_PASS') | |
ftp.cwd('[DIRECTORYNAME_IN_FTP_SERVER]') # navigate to desired directory in ftp server | |
filenames = ftp.nlst() # gives you a list of of files in the current directory | |
localfilepath = os.path.join('path','to','local','filename') # filename with complete path to where you would like to download the file | |
with open(localfilepath, 'wb') as local_file: | |
ftp.retrbinary('RETR [SOURCE_FILE_NAME]', local_file.write) # replace [SOURCE_FILE_NAME] with name of the file in ftp server that you want to download |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment