Skip to content

Instantly share code, notes, and snippets.

@shakyaabiral
Created September 13, 2018 04:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shakyaabiral/699feef6bd0b3457714f6c0f219e55bc to your computer and use it in GitHub Desktop.
Save shakyaabiral/699feef6bd0b3457714f6c0f219e55bc to your computer and use it in GitHub Desktop.
Python Download file from ftp
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