Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

sftp: unrecognized option: -

Rob Buijs March 10, 2022

Hi,

With a sftp script like the following one, I get a deployment faillure/

 
 - pipe: atlassian/sftp-deploy:0.5.8
variables:
DEBUG: 'true'
USER: 'wwwuser'
SERVER: '<servername>'
REMOTE_PATH: '<path>'
LOCAL_PATH: '${BITBUCKET_CLONE_DIR}/<deploy stuff>'
EXTRA_ARGS: "--exclude='.*'"

 

In the logs this is the sftp command that's generated. The empy '-' is the cause of the problem, but I can't find how to remove it.

sftp -b - -rp -v '--exclude='\''.*'\''' wwwuser@<servername>:<path>

3 answers

0 votes
Oleksandr Kyrdan
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 12, 2023

Hi @Rob Buijs

Thank you for your question!

Found this discussion and I'll try to help.

1. The empty '-' in the SFTP command is not an issue, pipe use it as part of -b option:

man sftp


-b batchfile
Batch mode reads a series of commands from an input batchfile instead of stdin. Since it lacks user interaction it should be used in conjunction
with non-interactive authentication to obviate the need to enter a password at connection time (see sshd(8) and ssh-keygen(1) for details).

A batchfile of ‘-’ may be used to indicate standard input. sftp will abort if any of the following commands fail: get, put, reget, reput, rename,
ln, rm, mkdir, chdir, ls, lchdir, chmod, chown, chgrp, lpwd, df, symlink, and lmkdir.

Termination on error can be suppressed on a command by command basis by prefixing the command with a ‘-’ character (for example, -rm /tmp/blah*).
Echo of the command may be suppressed by prefixing the command with a ‘@’ character. These two prefixes may be combined in any order, for example
-@ls /bsd.

2. The root cause for the error 

sftp: unrecognized option: -

is

EXTRA_ARGS: "--exclude='.*'"

that you try to pass into sftp, but sftp supports only:

sftp

usage: sftp [-46AaCfNpqrv] [-B buffer_size] [-b batchfile] [-c cipher]

          [-D sftp_server_path] [-F ssh_config] [-i identity_file]

          [-J destination] [-l limit] [-o ssh_option] [-P port]

          [-R num_requests] [-S program] [-s subsystem | sftp_server]

          destination

 

So, to have ability to exclude files you could use an alternative pipe:

atlassian/rsync-deploy

Example with an EXTRA_ARGS to exclude all files with '.txt' extension from deploy.

script:
  - pipe: atlassian/rsync-deploy:0.10.1
    variables:
      USER: 'ec2-user'
      SERVER: '127.0.0.1'
      REMOTE_PATH: '/var/www/build/'
      LOCAL_PATH: 'build'
      DEBUG: 'true'
      EXTRA_ARGS: '--exclude=*.txt'

CC: @Beau Liddell @Ankit Gupta 

Best regards,
Oleksandr Kyrdan

0 votes
Rob Buijs March 11, 2022

I have a ssh key for that account, not a password. I tried with a fake password, just to see what happened:

 

+ echo -e '\e[37mDEBUG: Executing echo "mput /opt/atlassian/pipelines/agent/build/avada-child-theme" | sshpass -p blieb sftp -o PubkeyAuthentication=no -rp -v --exclude='\''.*'\'' wwwuser@<server>:<path>\e[0m'
error remains the same:
sftp: unrecognized option: -
 
Beau Liddell
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 28, 2023

@Rob Buijswere you able to get this resolved? I'm facing the exact same issue.

Rob Buijs May 5, 2023

No, we never resolved this issue. We worked around it with scp

0 votes
Ankit Gupta March 10, 2022

Hi Rob,

You can try setting the PASSWORD variable for the pipe.

As per the code: https://bitbucket.org/atlassian/sftp-deploy/src/5166e989d76963957c12e2eb2c861d9cf6ba434d/pipe.sh#lines-100

In case the $PASSWORD var isn't defined, the other sftp cmd is triggered (which leads to error for you). Its possible the cmd doesn't work with PASSWORD based servers 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events