...

Deploy Files With GitHub Actions for FTP and SCP

deploy-files-with-github-actions-for-ftp-and-scp

GitHub actions for file deployment, FTP, and SCP

GitHub actions allows to make use of your GitHub-hosted code
repositories for running custom scripts for testing, deployment, and
much more.

  • Before You Get Started (Some Caveats and Prerequisites)
  • (Basically) How GitHub Actions Work
  • How to set up the GitHub FTP Action
  • Deploy Files to Unmanaged VPS Cloud Server With SCP (Added Security)

set up 2-factor authentication; which will add another layer of security on top of
your default username/password combination.

If you are interested in how to deploy files to your unmanaged VPS without using GitHub as a hosted service, check out our full guide on how to publish files to your server using Git.

ftp-deploy” action is ideal for deploying files to your
WordPress, shared hosting, or cPanel managed VPS accounts.

However, for cloud servers, the SCP method is recommended.

Edit the .github/workflows/main.yml file and place this code inside:

 on: push
name: Publish Website
jobs: FTP-Deploy-Action: name: FTP-Deploy-Action runs-on: ubuntu-latest steps: - uses: actions/checkout@v2.1.0 with: fetch-depth: 2 - name: FTP-Deploy-Action uses: SamKirkland/FTP-Deploy-Action@3.1.1 with: ftp-server: ftp://ftp.example.com:21/public_html ftp-username: userna5 ftp-password: ${{ secrets.FTP_PASSWORD }}

Note the following:

  • The file path set for the “ftp-server” option lands in “public_html”
    directory; make sure to update this as necessary for your project,
    or leave it as is to drop your project files in that directory.
  • The username “userna5” must be substituted with your correct cPanel
    or FTP username.
  • Alternatively, you could use a GitHub secret for your username in
    the same fashion as the FTP password.

Before committing and pushing your code to the repository, make sure
you have substituted all of the placeholder values, including
“FTP_PASSWORD” secret.

scp-action” action available from the GitHub website, SCP
offers an extra layer of security with SSH keys.

By default, your InMotion Hosting cloud VPS does not allow root login
via password authentication. SSH key authentication provides your
only way in. In order to allow GitHub to copy files to your server,
you will need to add your SSH private key and secure passphrase as a
GitHub secret, and, optionally, your username (which would be “root” by
default), hostname (or IP address).

Here is the “yaml” configuration for SCP:

 name: scp files
on: [push]
jobs: build: name: Build runs-on: ubuntu-latest steps: - uses: actions/checkout@master - name: copy file via ssh password uses: appleboy/scp-action@master with: host: ${{ secrets.HOST }} username: ${{ secrets.USERNAME }} key: ${{ secrets.SSH2 }} passphrase: ${{ secrets.PASSPHRASE }} port: ${{ secrets.PORT }} source: "index.html,textfiles/*" target: "/var/www/html"

As with the FTP action, this action will trigger on the GitHub server
when you push your changes to the repository.


Well done, you now know how to run GitHub actions for file deployment
with both the FTP and SCP file transfer methods. Be sure to leave a
comment or question if you have any issues or suggestions.

Discover more from WIREDGORILLA

Subscribe now to keep reading and get access to the full archive.

Continue reading