Performing FTP Operations on Linux with Lftp
Installing Lftp
sudo yum install lftp
Connecting to an FTP Server
Provide credentials directly in the URL:
lftp ftp://alice:secret@192.168.1.100:21
Alternatively, connect first and then authenticate interactively:
lftp 192.168.1.100
lftp 192.168.1.100:~> user alice
Password:
lftp alice@192.168.1.100:~>
Handling Character Encoding
When remote and local systems use different charsets, adjust the session settings:
set ftp:charset gbk
set file:charset utf-8
Navigating Directories
Change the local working directory before transferring files:
lcd /home/user/backups
Switch to the target remote directory:
cd /remote/archives
Uploading Files
Use mirror -R to recursively push a local directory:
mirror -R /home/user/backups/
For single or widlcard file uploads:
put report.log
mput *.csv
Downloading Files
Fetch an entire remote directory with mirror:
mirror /remote/archives/
Download individual files or patterns:
get -c dataset.tar.gz # -c enables resume support
mget *.txt
Finding Files on the Server
Search recursively for files matchign a pattern:
find . -name "*.conf"
List5000 List items in the current remote directory:
ls *.sh
Advanced Transfer Options
- Resume partial transfers and control concurrency:
pget -c -n 8 large_video.mp4
- Force a fresh listing (bypass local cache):
rels