January 2019
Beginner
318 pages
8h 23m
English
In this section, we are going to learn about downloading files from another machine using ftplib. For that, create a get_ftp_files.py script and write the following content in it:
import osfrom ftplib import FTPftp = FTP('your-ftp-domain-or-ip')with ftp: ftp.login('your-username','your-password') ftp.cwd('/home/student/work/') files = ftp.nlst() print(files) # Print the files for file in files: if os.path.isfile(file): print("Downloading..." + file) ftp.retrbinary("RETR " + file ,open("/home/student/testing/" + file, 'wb').write)ftp.close()
Run the script as follows:
student@ubuntu:~/work$ python3 get_ftp_files.py
You should get the following output:
Downloading...helloDownloading...hello.cDownloading...sample.txtDownloading...strip_hello ...
Read now
Unlock full access