Operating System - HP-UX
1819804 Members
3289 Online
109607 Solutions
New Discussion юеВ

SFTP connection using a shell script

 
Atheer Tariq
Occasional Advisor

SFTP connection using a shell script

I was using ftp to send files from one server to another:

************

ftp -nv << EOF
open $IP
user $USER $PASS
ascii
lcd $SOURCE
cd $DESTINATION
put $FILE
bye
EOF
echo "File transfered"

**************

I have the following questions:

1.) How can I do the same using now SFTP?
2.) How to disable auto-login?
3.) How to pass the user/pass to stfp through the shell script?

4 REPLIES 4
RAC_1
Honored Contributor

Re: SFTP connection using a shell script

1. Same as ftp script. But before doing that set hosts to do key based password authentication. You need to generate private and public keys and set them to do password less authentication. man ssh-keygen and search forums for setting it up.

2. If you are using hp ssh, it comes with tcp wrappers. Make use of /etc/hosts.deny file.

3. Same as 1. Set ssh/scp/sftp to password less authentication.
There is no substitute to HARDWORK
Atheer Tariq
Occasional Advisor

Re: SFTP connection using a shell script

Many thanks for your answer first!

What I need is a shell script to use to send a file using SFTP that I can put it in cron. what I can't do now is having the script using the login/pass he got to connect automatically to the remote server.

I'm not familiar with this private and public keys stuff. Is that really needed.
Darrel Louis
Honored Contributor

Re: SFTP connection using a shell script

Hi,

If you're ftp'ing for example from one unix server to another unix server you can use scp aswell.

http://docs.hp.com/en/6073/FAQ-SSH.pdf
http://www.hpuxconsulting.com/5004.ppt#256,46,Slide 46
http://www.openssh.org/faq.html

Goodluck,

Darrel
Mustafa Gulercan
Respected Contributor

Re: SFTP connection using a shell script

i wrote an example in 5 min.take a look;

#mget a file by using sftp--SAMPLE--

command='( sleep 1; echo '

command1='; sleep 1; echo mget ; sleep 1; echo exit; ) |
sftp username@
eval $s_command

s_command=$command$command1"> x_log 2>&1"
echo 'connecting to the server..'
rm ./x_log