Operating System - HP-UX
1825667 Members
4262 Online
109686 Solutions
New Discussion

Automating an sftp session

 
SOLVED
Go to solution
MRSG
Frequent Advisor

Automating an sftp session

I need to script the transfer of files using sftp.
How do I avoid entering the password interactively when using sftp to transfer files?

5 REPLIES 5
Geoff Wild
Honored Contributor

Re: Automating an sftp session

This site has a good tutorial (though for linux):

http://www.cvrti.utah.edu/~dustman/no-more-pw-ssh/

And here's some info on HP secure shell:

http://docs.hp.com/en/T1471-90011/ch01s10.html

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Steven E. Protter
Exalted Contributor

Re: Automating an sftp session

Shalom MRSG,

What I started with:
ftp -i -nv <<-EOF
user
ls
bye
EOF

What I ended up with:
sftp user@ <<-EOF

get
put
ls
bye
EOF

This has the disadvantage of having to hardcode the password in the script. It can be ehanced to read it from a more secure location.

I recommend scp

Its part of scp.

If you exchange public keys between servers it works like this:

scp user@servername:/

ex:

scp /etc/issue root@servername:/etc

One of these two docs will tell you how to do public key exchange:

http://www.hpuxconsulting.com/5003.ppt
http://www.hpuxconsulting.com/5004.ppt

I forget which and don't have time to check.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
MRSG
Frequent Advisor

Re: Automating an sftp session

Thanks for the pointers to docs on public and private key exchange.
I tried the method below but that doesn't work - I still get a password prompt.

sftp user@ <<-EOF

get
put
ls
bye
EOF

Looks as if you can't hardcode your password into an sftp script!
Jean-Yves Picard
Trusted Contributor
Solution

Re: Automating an sftp session

Hello,

you can generate a key pair on local host.

then you put your one line public key on .ssh/authorized_keys on remote host

be aware however that distant admin must uncomment lines in /etc/ssh/config_sshd
#RSAAuthentication yes
#PubkeyAuthentication yes

some admin wouldn't allow a ssh without keys, however as you are willing to establish a password less connection at first place....

If you feel this is doable, let us know I'll gave further instructions

Jean-Yves

MRSG
Frequent Advisor

Re: Automating an sftp session

I am going to use the RSA key exchange method as suggested. Thanks to all those who replied to my question.