Skip to content

Instantly share code, notes, and snippets.

@vojtasvoboda
Last active December 5, 2020 16:29
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save vojtasvoboda/8d6259e28095d5c99216e5bf44b7d320 to your computer and use it in GitHub Desktop.
Save vojtasvoboda/8d6259e28095d5c99216e5bf44b7d320 to your computer and use it in GitHub Desktop.
GitLab CI FTP deploy with mwienk/docker-lftp docker image
stages:
- test
- deploy
cache:
paths:
- vendor
# test job
test:
stage: test
image: edbizarro/gitlab-ci-pipeline-php:7.1
script:
- sudo composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts
- vendor/bin/phpunit --configuration phpunit.xml
# upload job, see https://lftp.yar.ru/lftp-man.html
upload:
stage: deploy
image: mwienk/docker-lftp:latest
script:
- lftp -e "set ftp:ssl-allow false; mirror -eRnv app web/app; exit;" -u $FTP_USERNAME,$FTP_PASSWORD $FTP_HOST
only:
- master
when: on_success
@vojtasvoboda
Copy link
Author

vojtasvoboda commented Nov 11, 2017

lftp options

Usage: mirror [OPTS] [remote [local]]

Mirror specified remote directory to local directory

 -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
 -s, --allow-suid       set suid/sgid bits according to remote site
     --allow-chown      try to set owner and group on files
     --ignore-time      ignore time when deciding whether to download
 -n, --only-newer       download only newer files (-c won't work)
 -r, --no-recursion     don't go to subdirectories
 -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
 -P, --parallel[=N]     download N files in parallel
 -i RX, --include RX    include matching files
 -x RX, --exclude RX    exclude matching files
                        RX is extended regular expression
 -v, --verbose[=N]      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=-

When using -R, the first directory is local and the second is remote.
If the second directory is omitted, basename of first directory is used.
If both directories are omitted, current local and remote directories are used.

lftp username could be also like that:

lftp ftp://username:password@host -e "set ftp:ssl-allow false; mirror -eRnv app app; exit;"

@markuskoehler
Copy link

markuskoehler commented Dec 29, 2018

I am getting "mirror: Address not available" although the same command works when manually entered... I am unable to find any information on that error. Any clue?

EDIT: it seems to be a DNS issue with the mwienk/docker-lftp:latest probably, because with IP instead of hostname it works?

@arxeiss
Copy link

arxeiss commented Dec 5, 2020

I know this is old, but I had some troubles with mirror command. Because some FTP servers are not keeping the modify time from the source. But changing it to upload time. I was dealing with it by using another tool (FTP Deployment) to handle changes and LFTP just to do parallel upload.
If you are interested, I wrote an article about it here: https://dev.to/arxeiss/parallel-incremental-ftp-deploy-in-ci-pipeline-2511

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment