lftp Mirror Command Exclude Matching Files [ Regex ]

The lftp command line FTP client provides the ability to exclude files that match a certain pattern when performing a mirror operation. You can use a regular expression (regex) to specify the pattern of files to exclude.

For example, to mirror a remote directory to a local directory while excluding all files with the extension .log, you can run the following command:

lftp -e "mirror -x *.log -v /remote/directory /local/directory; quit" -u username,password ftp.server.com

In this command, -x *.log specifies that all files with the .log extension should be excluded from the mirror operation. -v enables verbose output, so you can see the progress of the operation. -e allows you to specify multiple commands to run, in this case the mirror and quit commands. Finally, -u username,password specifies the FTP login credentials.

You can also exclude multiple file patterns by using multiple -x options. For example, to exclude files with the extensions .log and .bak, you can run the following command:

lftp -e "mirror -x *.log -x *.bak -v /remote/directory /local/directory; quit" -u username,password ftp.server.com

Leave a Comment