MeltingDog
MeltingDog

Reputation: 15424

How to SFTP with Github Actions?

I want to use Github actions to transfer files to a remote server via SFTP (only option for this server) when I push up to Github.

I am using this Action https://github.com/marketplace/actions/ftp-deploy

I have created a file in my repo in .github/workflows/main.yml and I have added:

on: push
name: Publish Website
jobs:
  FTP-Deploy-Action:
    name: FTP-Deploy-Action
    runs-on: ubuntu-latest
    steps:
    - uses: actions/[email protected]
      with:
        fetch-depth: 2
    - name: FTP-Deploy-Action
      uses: SamKirkland/[email protected]
      with:
        ftp-server: ${{ secrets.FTP_SERVER }}
        ftp-username: ${{ secrets.FTP_USERNAME }}
        ftp-password: ${{ secrets.FTP_PASSWORD }}

I have created a Secret for this repo which contains the following:

FTP_SERVER: sftp.server.com, FTP_USERNAME: user, FTP_PASSWORD: password

I can see the action running in Github but it errors out on the FTP-Deploy-Action task.

##[error]Input required and not supplied: ftp-server

This is in secrets and does work with Filezilla.

Would anyone know if I've set this up wrongly?

Upvotes: 6

Views: 16205

Answers (2)

Stefan
Stefan

Reputation: 12280

I tried a lot but SamKirkland/FTP-Deploy-Action did not work for me. Finally I found an alternative solution that does:

- name: deploy
  uses: pressidium/lftp-mirror-action@v1
  with:
    host: ${{ secrets.SFTP_URL }}
    port: ${{ secrets.SFTP_PORT }}
    user: ${{ secrets.SFTP_USER }}
    pass: ${{ secrets.SFTP_PASSWORD }}
    localDir: './toupload'
    remoteDir: '.'
    reverse: true

Upvotes: 3

Edward Romero
Edward Romero

Reputation: 3106

I was able to get it working on my own repo. I think the issue may be possibly on how your secrets were setup. That error usually shows when required parameters of a github action were not provided so curious if the keys are different or whether they were saved as empty. I would delete FTP_SERVER secret and create it again to be sure.

Workflow Success Run

Workflow Code

  - name: FTP-Deploy-Action
    uses: SamKirkland/[email protected]
    with:
      ftp-server: ${{ secrets.FTP_SERVER }}
      ftp-username: ${{ secrets.FTP_USERNAME }}
      ftp-password: ${{ secrets.FTP_PASSWORD }}
      local-dir: toupload

UPDATE: Added example per comment left below,

Example secret creation for reference. Basically create a secret per entry rather than comma separated grouped secret

enter image description here

Source: https://docs.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets

Upvotes: 6

Related Questions