January 2019
Beginner to intermediate
776 pages
19h 58m
English
Using the following script, let's set up a local FTP server. Once you have installed the FTP Server such as VSFTPD or FileZilla, you can upload a file to the logged-in user's home directory. You can specify the server address, login credentials, and filename as the input argument of your script.
Listing 5.2 gives the FTP upload example as follows:
#!/usr/bin/env python # Python Network Programming Cookbook, Second Edition -- Chapter - 5 # This program is optimized for Python 2.7.12 and Python 3.5.2. # It may run on any other version with/without modifications. import os import argparse import ftplib import getpass LOCAL_FTP_SERVER = 'localhost' LOCAL_FILE = 'readme.txt' def ftp_upload(ftp_server, username, password, file_name): ...
Read now
Unlock full access