How to use FTP in Python?

PythonServer Side ProgrammingProgramming

You can use the ftplib module in Python. It allows you to write programs that perform a variety of automated FTP jobs. You can easily connect to a FTP server to retrieve files and process them locally.


import ftplib
ftp = ftplib.FTP('', 'yourusername', 'your@email.address')
print "File List: "
files = ftp.dir()
ftp.cwd("/tmp") #change working directory to /tmp

Above code connects to a FTP server and prints the file list in the home directory of that server.

Published on 28-Dec-2017 07:05:45