How to Deploy to FTP Server from Gitlab Repository?

We can easily deploy our code from Gitlab repository to our FTP server by using Gitlab CI (Continuous Integration).

But What is Gitlab CI?

GitLab CI/CD is a part of GitLab, a web application with an API that stores its state in a database. It manages projects/builds and provides a nice user interface, besides all the features of GitLab. It is very useful for automating your deployment workflow.

It can do lot of things like Continuous Integration, Continuous Deployment, and Continuous Delivery support to build, test, and deploy your application.

But, today we gonna automate our task of Uploading last changed files to our FTP server by configuring Gitlab CI.

Let’s start by first creating a file named .gitlab-ci.yml in your root folder.

Then add the following code in your .gitlab-ci.yml file.

  HOST: ""
  USERNAME: "yourUserNameHere"
  PASSWORD: "yourPasswordHere"

    - apt-get update -qq && apt-get install -y -qq lftp
    - lftp -c "set ftp:ssl-allow no; open -u $USERNAME,$PASSWORD $HOST; mirror -Rnev ./ ./public_html --ignore-time --parallel=10 --exclude-glob .git* --exclude .git/"
    - master

The above code will push all your recently modified files in your Gitlab repository into public_html folder in your FTP Server root.

Just update the variables HOST, USERNAME and PASSWORD with your FTP Credentials and commit this file to your Gitlab Repository, you are good to go.

Now whenever you make changes in your master branch, Gitlab will automatically push your changes to your remote FTP server.

  • Unfortunately, this doesn’t work for me… the “- apt-get update…” lines fails. Gitlab says it can’t find apt-get. Any idea what I can do to resolve this as I’m not even able to install apt-get using pip. I’m a bit lost on how to get this working.

    image: python:alpine

    – pip install mkdocs
    # Add your custom theme if not inside a theme_dir
    # (
    # – pip install mkdocs-material
    # – pip install mkdocs-bootswatch

    stage: deploy
    environment: production
    – mkdocs build
    – mv site public
    – public
    – master

    – deploy

    stage: deploy
    # – pip install apt-get
    – apt-get update -y -qq && apt-get install -y -qq lftp
    – echo “FTP Deploy”
    – lftp -e “set ftp:ssl-allow no; open -u ${FTP_USERNAME},${FTP_PASSWORD} ftps://${FTP_HOST}; mirror -Rnev –ignore-time –parallel=10 –exclude-glob .git* –exclude .git/”
    name: production
    – master