From 3a6bd36ae13b4e560c96662641c97de31da6101d Mon Sep 17 00:00:00 2001 From: leoppro Date: Sun, 19 Sep 2021 18:36:15 +0800 Subject: [PATCH] Add an option named `sftp_only` to connect via sftp only --- README.md | 5 +++++ action.yml | 5 +++++ entrypoint.sh | 10 +++++++--- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index fb67e73..0e91568 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/action.yml b/action.yml index e478001..9cd1561 100644 --- a/action.yml +++ b/action.yml @@ -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' @@ -39,6 +43,7 @@ runs: - ${{ inputs.ssh_private_key }} - ${{ inputs.local_path }} - ${{ inputs.remote_path }} + - ${{ inputs.sftp_only }} - ${{ inputs.args }} branding: diff --git a/entrypoint.sh b/entrypoint.sh index 337102d..7b23391 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -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