Skip to content

Commit 9c4e464

Browse files
committed
v2.0.0
SFTP support!
1 parent 67f266c commit 9c4e464

File tree

4 files changed

+79
-32
lines changed

4 files changed

+79
-32
lines changed

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ LABEL "com.github.actions.description"="Deploy your website via FTP"
1010
LABEL "com.github.actions.icon"="upload-cloud"
1111
LABEL "com.github.actions.color"="orange"
1212

13-
RUN apk add lftp
13+
RUN apk update
14+
RUN apk add openssh sshpass lftp
1415

1516
COPY entrypoint.sh /entrypoint.sh
1617
RUN chmod 777 entrypoint.sh

README.md

Lines changed: 50 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ jobs:
1515
steps:
1616
- uses: actions/checkout@master
1717
- name: FTP-Deploy-Action
18-
uses: SamKirkland/FTP-Deploy-Action@master
18+
uses: SamKirkland/FTP-Deploy-Action@2.0.0
1919
env:
2020
FTP_SERVER: ftp.samkirkland.com
21-
FTP_USERNAME: ${{ secrets.FTP_USERNAME }}
21+
FTP_USERNAME: myFtpUserName
2222
FTP_PASSWORD: ${{ secrets.FTP_PASSWORD }}
2323
ARGS: --delete
2424
# --delete arg will delete files on the server if you've deleted them in git
@@ -28,29 +28,31 @@ jobs:
2828
2. Select the actions tab `(currently only for beta testers)`
2929
3. Select `Blank workflow file` or `Set up a workflow yourself`, if you don't see these options manually create a yaml file `Your_Project/.github/workflows/main.yml`
3030
4. Paste the above code into your file and save
31-
7. Now you need to add a few keys to the `secrets` section in your project, the following are required at a minimum. To add a `secret` go to the `Settings` tab in your project then select `Secrets`. Add a new `Secret` for each of the following
32-
* FTP_SERVER
33-
* FTP_USERNAME
34-
* FTP_PASSWORD
35-
* (see optional settings below)
31+
7. Now you need to add a key to the `secrets` section in your project. To add a `secret` go to the `Settings` tab in your project then select `Secrets`. Add a new `Secret` for `FTP_PASSWORD`
3632

3733
### Settings
38-
To add a `secret` go to the `Settings` tab in your project then select `Secrets`. Add a new `Secret` for each of the following.
39-
I recommend you use a secrets to store your FTP_USERNAME and FTP_PASSWORD.
40-
41-
| Key Name | Required? | Example | Default | Description |
42-
|----------------|-----------|-----------------------------|---------|-------------|
43-
| `FTP_SERVER` | Yes | ftp.samkirkland.com | N/A | FTP server name (you may need to specify a port) |
44-
| `FTP_USERNAME` | Yes | [email protected] | N/A | FTP account username |
45-
| `FTP_PASSWORD` | Yes | CrazyUniquePassword&%123 | N/A | FTP account password |
46-
| `LOCAL_DIR` | No | build | . (root project folder) | The local folder to copy, defaults to root project folder. Do NOT include slashes for folders. |
47-
| `REMOTE_DIR` | No | serverFolder | . (root FTP folder) | The remote folder to copy to, deafults to root FTP folder (I recommend you configure this on your server side instead of here). Do NOT include slashes for folders. |
48-
| `ARGS` | No | See `Commonly used ARGS` section below | N/A | Custom lftp arguments, this field is passed through directly into the lftp script. |
49-
50-
#### Commonly used ARGS
34+
Keys can be added directly to your .yml config file or referenced from your project `Secrets` storage.
35+
36+
To add a `secret` go to the `Settings` tab in your project then select `Secrets`.
37+
I recommend you store your FTP_PASSWORD as a secret.
38+
39+
| Key Name | Required? | Example | Default | Description |
40+
|----------------|-----------|----------------------------|-----------------|----------------------------------------------------------|
41+
| `FTP_SERVER` | Yes | ftp.samkirkland.com | N/A | FTP server name (you may need to specify a port) |
42+
| `FTP_USERNAME` | Yes | [email protected] | N/A | FTP account username |
43+
| `FTP_PASSWORD` | Yes | CrazyUniquePassword&%123 | N/A | FTP account password |
44+
| `METHOD` | No | ftp | ftp | Protocol used to deploy (ftp or sftp) |
45+
| `PORT` | No | 21 | ftp=21, sftp=22 | The port used to connect to server |
46+
| `LOCAL_DIR` | No | build | . (root project folder) | The local folder to copy, defaults to root project folder. Do NOT include slashes for folders. |
47+
| `REMOTE_DIR` | No | serverFolder | . (root FTP folder) | The remote folder to copy to, deafults to root FTP folder (I recommend you configure this on your server side instead of here). Do NOT include slashes for folders. |
48+
| `ARGS` | No | See `ARGS` section below | N/A | Custom lftp arguments, this field is passed through directly into the lftp script. |
49+
50+
#### ARGS
5151
Custom lftp arguments, this field is passed through directly into the lftp script. See [lftp's website](https://lftp.yar.ru/lftp-man.html) for all options.
5252
You can use as many arguments as you want, seperate them with a space
5353

54+
Below is an incomplete list of commonly used ARGS:
55+
5456
| Argument | Description |
5557
|------------------------|------------------------------------------------------------------------------------------------------|
5658
| `--verbose` | Outputs which files are being modified, useful for debugging |
@@ -94,15 +96,38 @@ jobs:
9496
run: ls
9597

9698
- name: FTP-Deploy-Action
97-
uses: SamKirkland/FTP-Deploy-Action@master
99+
uses: SamKirkland/FTP-Deploy-Action@2.0.0
98100
env:
99101
FTP_SERVER: ftp.samkirkland.com
100-
FTP_USERNAME: ${{ secrets.FTP_USERNAME }}
102+
FTP_USERNAME: myFTPUsername
101103
FTP_PASSWORD: ${{ secrets.FTP_PASSWORD }}
102104
LOCAL_DIR: build
103105
ARGS: --delete
104106
```
105107
108+
109+
## SFTP Example
110+
```yml
111+
on: push
112+
name: Publish Website over SFTP
113+
jobs:
114+
FTP-Deploy-Action:
115+
name: FTP-Deploy-Action
116+
runs-on: ubuntu-latest
117+
steps:
118+
- uses: actions/checkout@master
119+
120+
- name: FTP-Deploy-Action
121+
uses: SamKirkland/[email protected]
122+
env:
123+
FTP_SERVER: ftp.samkirkland.com
124+
FTP_USERNAME: mySFTPUsername
125+
FTP_PASSWORD: ${{ secrets.FTP_PASSWORD }}
126+
METHOD: sftp
127+
PORT: 7280
128+
ARGS: --delete
129+
```
130+
106131
### Log only dry run: Use this mode for testing
107132
Ouputs a list of files that will be created/modified to sync your source without making any actual changes
108133
```yml
@@ -115,10 +140,10 @@ jobs:
115140
steps:
116141
- uses: actions/checkout@master
117142
- name: FTP-Deploy-Action
118-
uses: SamKirkland/FTP-Deploy-Action@master
143+
uses: SamKirkland/FTP-Deploy-Action@2.0.0
119144
env:
120145
FTP_SERVER: ftp.samkirkland.com
121-
FTP_USERNAME: ${{ secrets.FTP_USERNAME }}
146+
FTP_USERNAME: myFTPUsername
122147
FTP_PASSWORD: ${{ secrets.FTP_PASSWORD }}
123148
ARGS: --delete --dry-run
124149
```
@@ -138,7 +163,7 @@ jobs:
138163
#### Deprecated main.workflow config (used for beta/legacy apps that haven't been migrated to .yaml workflows yet)
139164
```workflow
140165
action "FTP-Deploy-Action" {
141-
uses = "SamKirkland/FTP-Deploy-Action@master"
166+
uses = "SamKirkland/FTP-Deploy-Action@1.0.0"
142167
secrets = ["FTP_USERNAME", "FTP_PASSWORD", "FTP_SERVER"]
143168
}
144169
```
@@ -160,7 +185,6 @@ action "FTP-Deploy-Action" {
160185

161186

162187
#### ToDo
163-
- SFTP example
164188
- More examples
165189

166190
#### Pull Requests Welcome!

action.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: 'FTP Deploy'
2-
description: 'Syncs files via FTP to a remote server'
2+
description: 'Syncs files via FTP/SFTP to a remote server'
33
inputs:
44
ftp_server:
55
description: 'FTP server name (you may need to specify a port)'
@@ -10,14 +10,22 @@ inputs:
1010
ftp_password:
1111
description: 'FTP account password'
1212
required: true
13+
method:
14+
description: 'Protocol used to deploy (ftp or sftp)'
15+
required: false
16+
default: "ftp"
17+
port:
18+
description: 'The port used to connect to server'
19+
required: false
20+
default: "21"
1321
local_dir:
1422
description: 'The local folder to copy, defaults to root project folder'
1523
required: false
16-
default: ''
24+
default: ""
1725
remote_dir:
1826
description: 'The remote folder to copy to, deafults to root FTP folder (I recommend you configure this on your server side instead of here)'
1927
required: false
20-
default: ''
28+
default: ""
2129
ARGS:
2230
description: 'Passes through options into lftp'
2331
required: false
@@ -29,6 +37,8 @@ runs:
2937
- ${{ inputs.ftp_server }}
3038
- ${{ inputs.ftp_username }}
3139
- ${{ inputs.ftp_password }}
40+
- ${{ inputs.method }}
41+
- ${{ inputs.port }}
3242
- ${{ inputs.local_dir }}
3343
- ${{ inputs.remote_dir }}
3444
branding:

entrypoint.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,25 @@
44
set -eu
55

66
echo "Starting FTP Deploy"
7-
echo "Uploading files..."
87

98
WDEFAULT_LOCAL_DIR=${LOCAL_DIR:-"."}
109
WDEFAULT_REMOTE_DIR=${REMOTE_DIR:-"."}
1110
WDEFAULT_ARGS=${ARGS:-""}
11+
WDEFAULT_METHOD=${METHOD:-"ftp"}
12+
13+
if [ $WDEFAULT_METHOD = "sftp" ]; then
14+
WDEFAULT_PORT=${PORT:-"22"}
15+
echo "Establishing SFTP connection..."
16+
sshpass -p $FTP_PASSWORD sftp -o StrictHostKeyChecking=no -P $WDEFAULT_PORT $FTP_USERNAME@$FTP_SERVER
17+
echo "Connection established"
18+
else
19+
WDEFAULT_PORT=${PORT:-"21"}
20+
fi;
1221

13-
lftp $FTP_SERVER -u $FTP_USERNAME,$FTP_PASSWORD -e "set ftp:ssl-allow no; mirror $WDEFAULT_ARGS -R $WDEFAULT_LOCAL_DIR $WDEFAULT_REMOTE_DIR; quit"
22+
echo "Using $WDEFAULT_METHOD to connect to port $WDEFAULT_PORT"
23+
24+
echo "Uploading files..."
25+
lftp $WDEFAULT_METHOD://$FTP_SERVER:$WDEFAULT_PORT -u $FTP_USERNAME,$FTP_PASSWORD -e "set ftp:ssl-allow no; mirror $WDEFAULT_ARGS -R $WDEFAULT_LOCAL_DIR $WDEFAULT_REMOTE_DIR; quit"
1426

1527
echo "FTP Deploy Complete"
1628
exit 0

0 commit comments

Comments
 (0)