In this part of this series we will learn how to deal with directories operations: create, download, upload and mirroring.
Creating remote directories
> mkdir dir1 dir2 dir3
Create the hierarchy, if it doesn’t exist (creates the directories dir1, gtk, php and projects if they don’t exist)
> mkdir -p projects/php/gtk/dir1
> rm -r dir1 dir2 dir3
Download a directory (including subdirectories and files)
Download projects dir to the current local directory
> mirror projects
Download projects dir to the current local directory and rename it to projects-gtk
> mirror projects projects-gtk
Specify the local directory where you want to download it (note the slash at the end of the destination directory)
> mirror projects my-projects/
The behavior of mirror can be modified by options, some of the most important are:
- -n: only includes newer files
- -p: no keeps file permissions,let the ftp server set permissions
- -R: Reverse mirror, upload instead of download
- -i RX / -x RX: include / exclude files matching the pattern RX, RX is a regular expression.
- An example: upload all jpeg files from projects directory, keeping the directory structure, whose names contain any number and its local versions are newer than the remote versions and the ftp server sets the file permissions.
> mirror -Rnp -i '*[0-9]+*.jpeg' projects
- 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