In the first part of this series we learned what lftp is and how to execute some basic ftp operations as connecting/login/exploring an ftp site; in this part we will learn how to deal with file operations: download, upload and change permissions.
Download a file
> get file-name
Download several files
> get file1 file2 file3
Specify where you want to save locally
> get -O my-local-files/ file1 file2
Save with a different local name
> get file1 -o file1-diff-name > get file1 -o file1-diff-name file2 -o file2-diff-name
Upload a file
> put local-file-name
Upload multiple files
> put local-file1 local-file2 local-file3
Specify the remote location where you want to put
> put -O remote-dir/ login.class.php user.class.php
Save with a different remote name
> put user.class.php -o admin.class.php > put file1 -o file1-different-name file2 -o file2-different-name
Download files using wildcards
Download all jpeg files from the current remote directory
> mget *.jpeg
Download all the txt files from the current remote directory whose name begins with file followed by any character
> mget file?.txt
Download all txt files from the directory DIR, keeping the directory structure
> mget -d dir/*.txt
Download all files from all directories whose name starts with mydir, keeping the directory structure (subdirectories are excluded)
> mget -d mydir*/*
Upload files using wildcards
Upload all jpeg files from the current local directory
> mput *.jpeg
Upload all txt files from the current local directory whose name begins with file followed by any character
> mput file?.txt
Move or rename a file
> mv source dest
Rename the file file1.txt to file2.txt
> mv file1.txt file2.txt
Move the file file.txt from the current remote directory to doc remote directory (if you do not add a trailing /, lftp fails)
> mv file.txt doc/
Remove a file
> rm file-name
Delete all files from the current remote directory (directories are not included)
> mrm *
Change file permissions, the permissions must be specified in octal mode
> chmod perms file-name
Set read and write perms for the owner and group, read perms for the world.
> chmod 664 README.txt
Viewing the remote file content
> cat file-name > less file-name
lftp a sophisticated ftp client, 2 (4)
- lftp a sophisticated ftp client – exploring the site
- lftp a sophisticated ftp client – file handling
- lftp a sophisticated ftp client – directories handling
- lftp a sophisticated ftp client – advanced options