Skip to content

Commit

Permalink
Merge pull request #26 from leoppro/master
Browse files Browse the repository at this point in the history
Add an option named `sftp_only` to connect via sftp only
  • Loading branch information
wlixcc authored Feb 22, 2022
2 parents 28d6168 + 3a6bd36 commit c6e4d76
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@ sftp srever port , default `22`
**Required** `local_path` of you project, if you want put single file:use path like `./myfile`, if you want put directory: use path like `./static/*`, it will put all files under `static` directory. Default to `./*`(will put all files in your repo).

### `remote_path`

**Required** remote_path

### `sftp_only`

connection via sftp protocol only, the default value is `false`. If your port only accepts the sftp protocol, set this option to `true`. However, please note that when this option is set to `true`, the remote folder will not be created automatically.

### `args`
args of sftp cmd, E.g.`-o ConnectTimeout=5`

Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ inputs:
description: 'files will copy to under remote_path'
required: true
default: /
sftp_only:
description: 'connection via sftp protocol only'
required: false
default: false

args:
description: 'sftp args'
Expand All @@ -39,6 +43,7 @@ runs:
- ${{ inputs.ssh_private_key }}
- ${{ inputs.local_path }}
- ${{ inputs.remote_path }}
- ${{ inputs.sftp_only }}
- ${{ inputs.args }}

branding:
Expand Down
10 changes: 7 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@ printf "%s" "$4" >$TEMP_SSH_PRIVATE_KEY_FILE
# avoid Permissions too open
chmod 600 $TEMP_SSH_PRIVATE_KEY_FILE

echo 'ssh start'
if test $7 = "true"; then
echo "Connection via sftp protocol only, skip the command to create a directory"
else
echo 'ssh start'

ssh -o StrictHostKeyChecking=no -p $3 -i $TEMP_SSH_PRIVATE_KEY_FILE $1@$2 mkdir -p $6
ssh -o StrictHostKeyChecking=no -p $3 -i $TEMP_SSH_PRIVATE_KEY_FILE $1@$2 mkdir -p $6
fi

echo 'sftp start'
# create a temporary file containing sftp commands
printf "%s" "put -r $5 $6" >$TEMP_SFTP_FILE
#-o StrictHostKeyChecking=no avoid Host key verification failed.
sftp -b $TEMP_SFTP_FILE -P $3 $7 -o StrictHostKeyChecking=no -i $TEMP_SSH_PRIVATE_KEY_FILE $1@$2
sftp -b $TEMP_SFTP_FILE -P $3 $8 -o StrictHostKeyChecking=no -i $TEMP_SSH_PRIVATE_KEY_FILE $1@$2

echo 'deploy success'
exit 0
Expand Down

0 comments on commit c6e4d76

Please sign in to comment.