sftp through

General support questions
Post Reply
knzzz
Posts: 157
Joined: 2017/02/25 12:41:42

sftp through

Post by knzzz » 2018/03/08 15:38:01

Hi Team
can u someone pls tell a shell script for sftp

regards
Kanna

User avatar
TrevorH
Site Admin
Posts: 33202
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: sftp through

Post by TrevorH » 2018/03/08 16:10:14

can u someone pls tell a shell script for sftp
What does that even mean?
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

dimwit
Posts: 7
Joined: 2017/02/14 15:59:24

Re: sftp through

Post by dimwit » 2018/03/11 12:06:58

The sftp client offers the -b option by which you can pass it a text file that contains a sequence of sftp commands that you would like to get executed.

e.g.

Code: Select all

$ sftp -o identityfile=~/.ssh/some_key -b ~/scripts/file_with_sftp_cmds.txt someuser@somehost
If you only want to get a single or few sftp command(s) executed you can also pass -b a single dash, meaning read from stdin,
and either read from a here string or a pipe.

e.g. (n.b. newer versions of the sftp client now also support the -i option to pass the path to identity file, respectively the key pair to use)

Code: Select all

$ sftp -i ~/.ssh/some_key -b- someuser@somehost:some/path/relative/to/someusers/home <<<"ls -l"

or

$ echo -e "progress\nget /some/absolute/path/someuser/may/access/reading/some_file_glob*\nbye" | sftp -i ~/.ssh/some_key -b- someuser@somehost
But personally, I would always prefer the ssh and scp client commands for scripting over sftp,
and only use the latter where I don't have the two former alternatives, maybe because I am restricted to some anonymous SFTP server where I have no login account.

Post Reply