I want to mirror a directory using ftp and want to exclude certain subdirectories (such as logs) and file ending with *.cvs. How do I exclude files while mirroring using lftp command under Linux or Unix like operating systems?
lftp ftp client has many features that makes it a better choice for this kind of works The mirror command can be used and specified source directory to local target directory. If target directory ends with a slash, the source base name is appended to target directory name. You can exclude files and sub-directories. You can also use glob character such as *.
lftp command exclude syntax
The syntax is as follows:
mirror --exclude RX mirror --exclude-glob GP
In this example exclude logs directory, enter:
mirror --exclude logs/ --exclude
You can use --exclude multiple times:
mirror --exclude logs/ --exclude reports/ --exclude-glob *.bak --exclude-glob *~$
The following will exclude all *.cvs files:
mirror --exclude-glob *.cvs
Putting it all together
Create a file called mirror.http.lftp as follows:
set ftp:list-options -a set cmd:fail-exit true open ftp.cyberciti.biz.biz:/var/www/ lcd /nas06/backup/cyberciti.biz/ mirror --delete --exclude logs/ --exclude tmp/ --exclude-glob *~$ quit
Create or edit an authentication file called ~/.netrc - this file contains configuration and autologin information for the File Transfer Protocol client ftp and lftp:
machine ftp.cyberciti.biz login MyUserNameHer password myPassWordHere
Save and close the file. Run the job as follows:
lftp -f mirror.http.lftp
OR
lftp -f mirror.http.lftp > ~/mirror.http.lftp.log
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop














{ 0 comments… add one now }