Can I put comments in a sftp batch file script?

2

2

I'm using sftp batch scripts to automate some file transfers.

Is there a syntax for putting comments in the batch files?

For example:

sftp -b mybatchscript.sftp nick@server

Where mybatchscript.sftp contains:

cd mydir
get *.txt
get *.dat

I'd like to have something similar to:

cd mydir
# Fetch all text files
get *.txt
# Fetch all data files
get *.dat

Thanks.

EDIT

Ok - it turns out that my guess at a commenting format works just fine.

Nick Pierpoint

Posted 2009-10-16T10:55:24.593

Reputation: 505

Answers

1

It might depend on the sftp server, but with mine using # Whatever as a comment works fine just like you wrote. If it doesn't, you could always do that and just process that file with grep:

grep -v '^#' myBactchScriptNotes.sftp > myBatchScript

Kyle Brandt

Posted 2009-10-16T10:55:24.593

Reputation: 3 089

2

The commands are interpreted by an SFTP client, so it depends on the client, not a server (contrary to the answer by @KyleBrandt).

With the OpenSSH sftp (the most widespread one), lines starting with the # are indeed ignored.

# Download text files
get *.txt

It does not seem to be documented in the sftp man page, but it follows (documented) convention from OpenSSH configuration files such as sshd_config:

Lines starting with `#' and empty lines are interpreted as comments.

Martin Prikryl

Posted 2009-10-16T10:55:24.593

Reputation: 13 764