1824189 Members
5173 Online
109669 Solutions
New Discussion юеВ

SFTP script

 
M. Tariq Ayub
Regular Advisor

SFTP script

I am trying to write a automated sftp script. Does any one have one. i will use key instead of password.
3 REPLIES 3
Ermin Borovac
Honored Contributor

Re: SFTP script

You can put your commands in a batch file and run sftp with -b option.

-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. A
batchfile of `-' may be used to indicate standard input. sftp
will abort if any of the following commands fail: get, put,
rename, ln, rm, mkdir, chdir, ls, lchdir, chmod, chown, chgrp,
lpwd 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* ).
M. Tariq Ayub
Regular Advisor

Re: SFTP script

I want to know details about sftp. how it works. how can i program through it.
Steven E. Protter
Exalted Contributor

Re: SFTP script

sftp is secure ftp.

It is part of the openssh package and does authentication and sessions encrypted. This makes it a secure replacement for ftp.

Hence the Name.

You have some nice options though.

You can set up password free sftp or use a slightly modified ftp script. Password free is more secure, because it uses public key exchange. A sftp or ftp script normally involves a password in a script.

Here is a typical ftp script.


ftp -nv 10.201.10.1 </tmp/get_logftp01.$$
user ${USER}${PASS}
cd${COLLECT}
get${FILE1}
bye
FTPEOF

The SFTP script would look like this:

sftp username@10.201.10.1 </tmp/get_logftp01.$$
user ${USER}${PASS}
cd${COLLECT}
get${FILE1}
bye
FTPEOF

Note that in this example the username, passwrd cd directory and file information input into variables prior to the script snippet. This baby also creates a log file.

Now, if you want to learn about exchanging public keys, you can read this Chris Vail document(attached) or attend a seminar I'm giving at HP World in San Francisco August 14-18.

SEP
Contact form that mail's me offline:
http://www.isnamerica.com/contactsep.shtml
Please enter text telling me WHY you are using this contact form.

Thanks.
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