1. Connecting to FTP from the Command Line (Windows/Linux/macOS)
bash
ftp ftp.servername.com
After logging in:
bash
Username: username
Password: password
To download a file:
bash
get file.txt
To upload a file:
bash
put local_file.txt
🐍 2. Uploading a File via FTP with Python (ftplib)
python
from ftplib import FTP
ftp = FTP('ftp.servername.com')
ftp.login(user='username', passwd='password')
with open('file.txt', 'rb') as file:
ftp.storbinary('STOR file.txt', file)
ftp.quit()
This code uploads the local file named file.txt to the server.
🖥️ 3. Setting Up an FTP Server with vsftpd (Ubuntu)
bash
sudo apt update
sudo apt install vsftpd
Edit the configuration file:
bash
sudo nano /etc/vsftpd.conf
Recommended settings:
conf
anonymous_enable=NO
local_enable=YES
write_enable=YES
chroot_local_user=YES
Restart the service:
bash
sudo systemctl restart vsftpd
🔐 4. Connecting with Secure FTP (SFTP)
SFTP runs over SSH. To connect:
bash
sftp username@servername.com
To upload a file:
bash
put file.txt
To download a file:
bash
get file.txt
