LFTP - Deploy an application in command line

Here we will see how to automatically deploy an application with lftp in command line.
Friday, December 31, 2021

Installation

First, we need to install lftp on our system:

Terminal window
# On Debian / Ubuntu
sudo apt install lftp
# On Fedora
yum install lftp
# On Alpine
apk add lftp

Use lftp

Here, we define 3 variables:

  • $(FTP_USERNAME) represents the FTP username ; example: alex
  • $(FTP_PASSWORD) represents the FTP password ; example: SuperSpiciesMeltingMountains67
  • $(FTP_HOSTNAME) represents the FTP host ; example: ftp://alexandre@ftp.cluster473.hosting.domain.net
Terminal window
lftp -u $(FTP_USERNAME),$(FTP_PASSWORD) -e "mirror --ignore-time --reverse --parallel --verbose --delete -R ./ www/; quit" $(FTP_HOSTNAME)

This line uses lftp to connect to the ftp server.

The command mirror is used to synchronize local files and server files together. Here we sync the local ./ directory with the www/ FTP directory.

Manual

If you need more informations, here are the available flags from the manual:

-c, --continue Continue a mirror job if possible
-e, --delete Delete files not present at remote site
--delete-first Delete old files before transferring new ones
--depth-first Descend into subdirectories before transferring files
-s, --allow-suid Set suid/sgid bits according to remote site
--allow-chown Try to set owner and group on files
--ascii Use ascii mode transfers (implies --ignore-size)
--ignore-time Ignore time when deciding whether to download
--ignore-size Ignore size when deciding whether to download
--only-missing Download only missing files
--only-existing Download only files already existing at target
-n, --only-newer Download only newer files (-c won't work)
--no-empty-dirs Don't create empty directories (implies --depth-first)
-r, --no-recursion Don't go to subdirectories
--no-symlinks Don't create symbolic links
-p, --no-perms Don't set file permissions
--no-umask Don't apply umask to file modes
-R, --reverse Reverse mirror (put files)
-L, --dereference Download symbolic links as files
-N, --newer-than=SPEC Download only files newer than specified time
--on-change=CMD Execute the command if anything has been changed
--older-than=SPEC Download only files older than specified time
--size-range=RANGE Download only files with size in specified range
-P, --parallel[=N] Download N files in parallel
--use-pget[-n=N] Use pget to transfer every single file
--loop Loop until no changes found
-i RX, --include RX include matching files
-x RX, --exclude RX exclude matching files
-I GP, --include-glob GP include matching files
-X GP, --exclude-glob GP exclude matching files
-v, --verbose[=level] Verbose operation
--log=FILE Write lftp commands being executed to FILE
--script=FILE Write lftp commands to FILE, but don't execute them
--just-print, --dry-run Same as --script=-
--use-cache Use cached directory listings
--Remove-source-files Remove files after transfer (use with caution)
-a Same as --allow-chown --allow-suid --no-umask

Thank you for reading my post ! I hope it helped !


Recommended articles