How to use FTP in Python?


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.

example

import ftplib
ftp = ftplib.FTP('ftp.yourserver.com', 'yourusername', 'your@email.address')
print "File List: "
files = ftp.dir()
print(files)
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.

Updated on: 18-Feb-2020

248 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements