Skip to content

Commit 43fdbd5

Browse files
committed
Updated the documentation; Added verbose and free FTP settings.
1 parent 4c5272a commit 43fdbd5

3 files changed

Lines changed: 156 additions & 70 deletions

File tree

.idea/runConfigurations/Dockerfile.xml

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
1-
# FTP Deployment: Github Action
2-
3-
This GitHub action copy the files via FTP from your Git project to your server in a specific path.
1+
# FTP Deployment: GitHub Action
42

3+
This GitHub action copies the files via FTP from your Git project to your server in a specific path.
54

65
## Usage Example
76

8-
Add this code in `.github/workflows/your_action.yml`.
7+
Add this code in `./.github/workflows/your_action.yml`.
98

10-
More about Github "secrets" in this article:
9+
More about GitHub "secrets" in this article:
1110
[Creating and storing encrypted secrets][1].
1211

1312
```yaml
1413
name: CI -> Deploy to My website
1514
on:
1615
push:
17-
branches: [ master, Development ]
16+
branches: [ main, development ]
1817
jobs:
1918
build:
2019
runs-on: ubuntu-latest
2120
steps:
22-
- uses: actions/checkout@v2
21+
- uses: actions/checkout@v4
2322
# Here is the deployment action
2423
- name: Upload from public_html via FTP
2524
uses: airvzxf/ftp-deployment-action@latest
@@ -28,50 +27,50 @@ jobs:
2827
user: ${{ secrets.FTP_USERNAME }}
2928
password: ${{ secrets.FTP_PASSWORD }}
3029
local_dir: "./public_html"
31-
delete: "false"
3230
```
3331
34-
Optional, you can get the live version which has the last commits using the `master` branch like this:<br>
35-
`uses: airvzxf/ftp-deployment-action@master`
36-
32+
Optionally, you can get the live version which has the last commits using the `master` branch like this:
33+
`uses: airvzxf/ftp-deployment-action@master`.
3734

3835
## Settings
3936

40-
Usually the 0 (zero) values means unlimited or infinite.
41-
42-
Option | Description | Required | Default | Example
43-
--- | --- | --- | --- | ---
44-
server | FTP Server. | Yes | N/A | rovisoft.net
45-
user | FTP Username. | Yes | N/A | myself@rovisoft.net
46-
password | FTP Password. | Yes | N/A | ExampleOnlyAlphabets
47-
local_dir | Local directory. | No | "./" | "./public_html"
48-
remote_dir | Remote directory. | No | "./" | "/www/user/home"
49-
delete | Delete all the files inside of the remote directory before the upload process. | No | false | N/A
50-
max_retries | Times that the `lftp` will be executed if an error occurred. | No | 10 | N/A
51-
no_symlinks | Do not create symbolic links. | No | true | N/A
52-
ftp_ssl_allow | FTP - Allow SSL encryption | No | false | N/A
53-
ftp_use_feat | FTP - FEAT: Determining what extended features the FTP server supports. | No | false | N/A
54-
ftp_nop_interval | FTP - Delay in seconds between NOOP commands when downloading tail of a file. | No | 2 | N/A
55-
net_max_retries | NET - Maximum number of operation without success.<br> 0 unlimited.<br> 1 no retries. | No | 1 | N/A
56-
net_persist_retries | NET - Ignore hard errors.<br> When reply 5xx errors or there is too many users. | No | 5 | N/A
57-
net_timeout | NET - Sets the network protocol timeout. | No | 15s | N/A
58-
dns_max_retries | DNS - 0 no limit trying to lookup an address otherwise try only this number of times. | No | 8 | N/A
59-
dns_fatal_timeout | DNS - Time for DNS queries.<br> Set to "never" to disable. | No | 10s | N/A
60-
61-
More information in the official site for [lftp - Manual pages][2]
37+
Usually the zero values mean unlimited or infinite. This table is based on the default values on `lftp-4.9.2`.
38+
39+
| Option | Description | Required | Default | Example |
40+
|---------------------|---------------------------------------------------------------------------------------|----------|---------|---------------------------------------------------------------------------------------------------|
41+
| server | FTP Server. | Yes | N/A | rovisoft.net |
42+
| user | FTP Username. | Yes | N/A | myself@rovisoft.net |
43+
| password | FTP Password. | Yes | N/A | ExampleOnlyAlphabets |
44+
| local_dir | Local directory. | No | "./" | "./public_html" |
45+
| remote_dir | Remote directory. | No | "./" | "/www/user/home" |
46+
| max_retries | Times that the `lftp` command will be executed if an error occurred. | No | 10 | N/A |
47+
| delete | Delete all the files inside of the remote directory before the upload process. | No | false | N/A |
48+
| no_symlinks | Do not create symbolic links. | No | false | N/A |
49+
| mirror_verbose | Mirror verbosity level. | No | 1 | N/A |
50+
| ftp_ssl_allow | FTP - Allow SSL encryption | No | true | N/A |
51+
| ftp_use_feat | FTP - FEAT: Determining what extended features the FTP server supports. | No | true | N/A |
52+
| ftp_nop_interval | FTP - Delay in seconds between NOOP commands when downloading tail of a file. | No | 2 | N/A |
53+
| net_max_retries | NET - Maximum number of operation without success.<br> 0 unlimited.<br> 1 no retries. | No | 1 | N/A |
54+
| net_persist_retries | NET - Ignore hard errors.<br> When reply 5xx errors or there is too many users. | No | 5 | N/A |
55+
| net_timeout | NET - Sets the network protocol timeout. | No | 15s | N/A |
56+
| dns_max_retries | DNS - 0 no limit trying to lookup an address otherwise try only this number of times. | No | 8 | N/A |
57+
| dns_fatal_timeout | DNS - Time for DNS queries.<br> Set to "never" to disable. | No | 10s | N/A |
58+
| lftp_settings | Any other settings that you find in the MAN pages for the LFTP package. | No | "" | "set cache:cache-empty-listings true; set cmd:status-interval 1s; set http:user-agent 'firefox';" |
59+
60+
More information on the official site for [lftp - Manual pages][2].
6261

6362
Example with NO DEFAULT settings:
6463

6564
```yaml
6665
name: CI -> Deploy to My website
6766
on:
6867
push:
69-
branches: [ master, Development ]
68+
branches: [ main, development ]
7069
jobs:
7170
build:
7271
runs-on: ubuntu-latest
7372
steps:
74-
- uses: actions/checkout@v2
73+
- uses: actions/checkout@v4
7574
# Here is the deployment action
7675
- name: Upload from public_html via FTP
7776
uses: airvzxf/ftp-deployment-action@latest
@@ -92,19 +91,23 @@ jobs:
9291
net_timeout: "13s"
9392
dns_max_retries: "17"
9493
dns_fatal_timeout: "never"
94+
lftp_settings: "set cache:cache-empty-listings true; set cmd:status-interval 1s; set http:user-agent 'firefox';"
9595
```
9696

9797
## NOTES
9898

9999
Main features:
100-
- Copy all the files inside of the specific folder from your Github repository to the specific folder in your server.
100+
101+
- Copy all the files inside the specific folder from your GitHub repository to the specific folder in your server.
101102
- Option to delete all the files in the specific remote folder before the upload.
102-
- Use Alpine container means small size and faster creation of the container.
103+
- Using Alpine container means small size and faster creation of the container.
103104
- Show messages in the console logs for every executed command.
104105

105106
TODOs:
107+
106108
- Add options for exclude delete files.
107-
- Take all the logs from the Linux container then attach all into the Workflow Artifacts, to review unknown errors.
109+
- Take all the logs from the Linux container then attach all into the Workflow Artifacts, to review unknown errors.
108110

109111
[1]: https://docs.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets
110-
[2]: http://lftp.tech/lftp-man.html
112+
113+
[2]: https://lftp.yar.ru/lftp-man.html

init.sh

Lines changed: 114 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
#!/bin/sh -e
22

3+
# ------------------------------------------------------------------------------
4+
# Display environment variables.
5+
# ------------------------------------------------------------------------------
36
echo "=== Environment variables ==="
47
echo "INPUT_SERVER: ${INPUT_SERVER}"
58
echo "INPUT_USER: ${INPUT_USER}"
69
echo "INPUT_PASSWORD: ${INPUT_PASSWORD}"
710
echo "INPUT_LOCAL_DIR: ${INPUT_LOCAL_DIR}"
811
echo "INPUT_REMOTE_DIR: ${INPUT_REMOTE_DIR}"
9-
echo "INPUT_DELETE: ${INPUT_DELETE}"
1012
echo "INPUT_MAX_RETRIES: ${INPUT_MAX_RETRIES}"
13+
echo "INPUT_DELETE: ${INPUT_DELETE}"
1114
echo "INPUT_NO_SYMLINKS: ${INPUT_NO_SYMLINKS}"
15+
echo "INPUT_MIRROR_VERBOSE: ${INPUT_MIRROR_VERBOSE}"
1216
echo "INPUT_FTP_SSL_ALLOW: ${INPUT_FTP_SSL_ALLOW}"
1317
echo "INPUT_FTP_USE_FEAT: ${INPUT_FTP_USE_FEAT}"
1418
echo "INPUT_FTP_NOP_INTERVAL: ${INPUT_FTP_NOP_INTERVAL}"
@@ -17,60 +21,134 @@ echo "INPUT_NET_PERSIST_RETRIES: ${INPUT_NET_PERSIST_RETRIES}"
1721
echo "INPUT_NET_TIMEOUT: ${INPUT_NET_TIMEOUT}"
1822
echo "INPUT_DNS_MAX_RETRIES: ${INPUT_DNS_MAX_RETRIES}"
1923
echo "INPUT_DNS_FATAL_TIMEOUT: ${INPUT_DNS_FATAL_TIMEOUT}"
24+
echo "INPUT_LFTP_SETTINGS: ${INPUT_LFTP_SETTINGS}"
2025
echo ""
2126
echo "=== Current location ==="
2227
pwd
23-
ls -lha
2428
echo ""
2529

26-
FTP_SETTINGS="set ftp:ssl-allow ${INPUT_FTP_SSL_ALLOW};"
27-
FTP_SETTINGS="${FTP_SETTINGS} set ftp:use-feat ${INPUT_FTP_USE_FEAT};"
28-
FTP_SETTINGS="${FTP_SETTINGS} set ftp:nop-interval ${INPUT_FTP_NOP_INTERVAL};"
29-
FTP_SETTINGS="${FTP_SETTINGS} set net:max-retries ${INPUT_NET_MAX_RETRIES};"
30-
FTP_SETTINGS="${FTP_SETTINGS} set net:persist-retries ${INPUT_NET_PERSIST_RETRIES};"
31-
FTP_SETTINGS="${FTP_SETTINGS} set net:timeout ${INPUT_NET_TIMEOUT};"
32-
FTP_SETTINGS="${FTP_SETTINGS} set dns:max-retries ${INPUT_DNS_MAX_RETRIES};"
33-
FTP_SETTINGS="${FTP_SETTINGS} set dns:fatal-timeout ${INPUT_DNS_FATAL_TIMEOUT};"
30+
# ------------------------------------------------------------------------------
31+
# Set the LFTP setting.
32+
# ------------------------------------------------------------------------------
33+
FTP_SETTINGS=""
3434

35-
MIRROR_COMMAND="mirror --continue --reverse"
35+
# ftp:ssl-allow
36+
if [ -n "${INPUT_FTP_SSL_ALLOW}" ]; then
37+
FTP_SETTINGS="${FTP_SETTINGS} set ftp:ssl-allow ${INPUT_FTP_SSL_ALLOW};"
38+
else
39+
FTP_SETTINGS="${FTP_SETTINGS} set ftp:ssl-allow true;"
40+
fi
41+
42+
# ftp:use-feat
43+
if [ -n "${INPUT_FTP_USE_FEAT}" ]; then
44+
FTP_SETTINGS="${FTP_SETTINGS} set ftp:use-feat ${INPUT_FTP_USE_FEAT};"
45+
else
46+
FTP_SETTINGS="${FTP_SETTINGS} set ftp:use-feat true;"
47+
fi
48+
49+
# ftp:nop-interval
50+
if [ -n "${INPUT_FTP_NOP_INTERVAL}" ]; then
51+
FTP_SETTINGS="${FTP_SETTINGS} set ftp:nop-interval ${INPUT_FTP_NOP_INTERVAL};"
52+
else
53+
FTP_SETTINGS="${FTP_SETTINGS} set ftp:nop-interval 2;"
54+
fi
55+
56+
# net:max-retries
57+
if [ -n "${INPUT_NET_MAX_RETRIES}" ]; then
58+
FTP_SETTINGS="${FTP_SETTINGS} set net:max-retries ${INPUT_NET_MAX_RETRIES};"
59+
else
60+
FTP_SETTINGS="${FTP_SETTINGS} set net:max-retries 1;"
61+
fi
62+
63+
# net:persist-retries
64+
if [ -n "${INPUT_NET_PERSIST_RETRIES}" ]; then
65+
FTP_SETTINGS="${FTP_SETTINGS} set net:persist-retries ${INPUT_NET_PERSIST_RETRIES};"
66+
else
67+
FTP_SETTINGS="${FTP_SETTINGS} set net:persist-retries 5;"
68+
fi
69+
70+
# net:timeout
71+
if [ -n "${INPUT_NET_TIMEOUT}" ]; then
72+
FTP_SETTINGS="${FTP_SETTINGS} set net:timeout ${INPUT_NET_TIMEOUT};"
73+
else
74+
FTP_SETTINGS="${FTP_SETTINGS} set net:timeout 15s;"
75+
fi
76+
77+
# dns:max-retries
78+
if [ -n "${INPUT_DNS_MAX_RETRIES}" ]; then
79+
FTP_SETTINGS="${FTP_SETTINGS} set dns:max-retries ${INPUT_DNS_MAX_RETRIES};"
80+
else
81+
FTP_SETTINGS="${FTP_SETTINGS} set dns:max-retries 8;"
82+
fi
83+
84+
# dns:fatal-timeout
85+
if [ -n "${INPUT_DNS_FATAL_TIMEOUT}" ]; then
86+
FTP_SETTINGS="${FTP_SETTINGS} set dns:fatal-timeout ${INPUT_DNS_FATAL_TIMEOUT};"
87+
else
88+
FTP_SETTINGS="${FTP_SETTINGS} set dns:fatal-timeout 10s;"
89+
fi
90+
91+
# Any manual settings
92+
if [ -n "${INPUT_LFTP_SETTINGS}" ]; then
93+
FTP_SETTINGS="${FTP_SETTINGS} ${INPUT_LFTP_SETTINGS};"
94+
fi
3695

96+
# Remove first space in settings variable
97+
if [ -n "${FTP_SETTINGS}" ]; then
98+
FTP_SETTINGS="${FTP_SETTINGS#"${FTP_SETTINGS%%[![:space:]]*}"}"
99+
fi
100+
101+
# Max number of retries
37102
if [ -z "${INPUT_MAX_RETRIES}" ]; then
38103
INPUT_MAX_RETRIES="10"
39104
fi
40105

106+
# Local path to get the directories
41107
if [ -z "${INPUT_LOCAL_DIR}" ]; then
42108
INPUT_LOCAL_DIR="./"
43109
else
44-
if [ "${INPUT_LOCAL_DIR}" != "./" ]; then
45-
INPUT_LOCAL_DIR="${INPUT_LOCAL_DIR}/"
46-
fi
110+
INPUT_LOCAL_DIR="${INPUT_LOCAL_DIR}/"
47111
fi
48112

113+
# Remote path to put the directories
49114
if [ -z "${INPUT_REMOTE_DIR}" ]; then
50115
INPUT_REMOTE_DIR="./"
51116
else
52-
if [ "${INPUT_REMOTE_DIR}" != "./" ]; then
53-
INPUT_REMOTE_DIR="${INPUT_REMOTE_DIR}/"
54-
fi
117+
INPUT_REMOTE_DIR="${INPUT_REMOTE_DIR}/"
118+
fi
119+
120+
# Reverse mirror which uploads or updates a directory tree on server
121+
MIRROR_COMMAND="mirror --continue --reverse"
122+
123+
# Mirror verbosity level
124+
if [ -n "${INPUT_MIRROR_VERBOSE}" ]; then
125+
MIRROR_COMMAND="${MIRROR_COMMAND} --verbose=${INPUT_MIRROR_VERBOSE}"
126+
else
127+
MIRROR_COMMAND="${MIRROR_COMMAND} --verbose=1"
55128
fi
56129

130+
# Don't create symbolic links
57131
if [ "${INPUT_NO_SYMLINKS}" = "true" ]; then
58132
MIRROR_COMMAND="${MIRROR_COMMAND} --no-symlinks"
59133
fi
60134

135+
# Delete files not present at the source
61136
if [ "${INPUT_DELETE}" = "true" ]; then
62137
MIRROR_COMMAND="${MIRROR_COMMAND} --delete"
63138
fi
64139

140+
# ------------------------------------------------------------------------------
141+
# Display LFTP settings.
142+
# ------------------------------------------------------------------------------
65143
echo "=== Directories ==="
66144
echo "INPUT_LOCAL_DIR: ${INPUT_LOCAL_DIR}"
67145
echo "INPUT_REMOTE_DIR: ${INPUT_REMOTE_DIR}"
68146
echo ""
69-
echo "=== List local directory | ${INPUT_LOCAL_DIR} ==="
147+
echo "=== List local directory ==="
148+
echo "${INPUT_LOCAL_DIR}"
70149
ls -lha "${INPUT_LOCAL_DIR}"
71150
echo ""
72-
echo "=== LFTP ==="
73-
echo "lftp"
151+
echo "=== LFTP Settings ==="
74152
echo " FTP_SETTINGS -> ${FTP_SETTINGS}"
75153
echo " MIRROR_COMMAND -> ${MIRROR_COMMAND}"
76154
echo " INPUT_LOCAL_DIR -> ${INPUT_LOCAL_DIR}"
@@ -79,18 +157,20 @@ echo " INPUT_MAX_RETRIES -> ${INPUT_MAX_RETRIES}"
79157
echo ""
80158
echo "=== * NOTE * ==="
81159
echo "The upload should be fast depends how many files and what size they have."
82-
echo "If the process take for several minutes, please stop the job and run it again."
83-
echo ""
160+
echo "If the process take for several minutes or hours, please stop the job and run it again."
84161

162+
# ------------------------------------------------------------------------------
163+
# Execute the LFTP actions.
164+
# ------------------------------------------------------------------------------
85165
COUNTER=1
86166
SUCCESS=""
87167

88-
until [ ${COUNTER} -gt ${INPUT_MAX_RETRIES} ]; do
168+
while true; do
89169
echo ""
90-
echo "Try #: ${COUNTER}"
91-
echo "# ---------------------------------------------"
170+
echo "Try #${COUNTER}"
171+
echo "-------"
172+
92173
lftp \
93-
--debug \
94174
-u "${INPUT_USER}","${INPUT_PASSWORD}" \
95175
"${INPUT_SERVER}" \
96176
-e "${FTP_SETTINGS} ${MIRROR_COMMAND} ${INPUT_LOCAL_DIR} ${INPUT_REMOTE_DIR}; quit;" &&
@@ -100,10 +180,17 @@ until [ ${COUNTER} -gt ${INPUT_MAX_RETRIES} ]; do
100180
break
101181
fi
102182

103-
sleep 1m
104183
COUNTER=$((COUNTER + 1))
184+
if [ ${COUNTER} -gt ${INPUT_MAX_RETRIES} ]; then
185+
break
186+
fi
187+
188+
sleep 1m
105189
done
106190

191+
# ------------------------------------------------------------------------------
192+
# Display the status of the LFTP actions.
193+
# ------------------------------------------------------------------------------
107194
if [ -z "${SUCCESS}" ]; then
108195
echo ""
109196
echo "=============================="

0 commit comments

Comments
 (0)