Solved

SFTP - passing a password from within a script

Posted on 2002-07-01
7
23,745 Views
Last Modified: 2010-08-05
I just about have everything working with SFTP.  I tested SFTP using a batch file to pass it the commands and it works great.  The problem I have though is it prompts me to put a password before it starts reading the file and processing the commands.

Here is the syntax I use from the command line:

sftp -b /path/genPluginBatch webuser@webhost

I tried putting the password as the first line in the batch file, genPluginBatch, but it sees this as a bad command.  Any idea how I would pass the password from within a script?

Just so you know I also tried the following from within the script:

sftp wsadmin@uscscdev7 webuser@webhost <<EOF
<password>
cd /opt/WebSphere/AppServer/config
put plugin-cfg.xml
bye
EOF


Thanks,

Lisa
0
Comment
Question by:lphillips120898
7 Comments
 
LVL 29

Expert Comment

by:MikeOM_DBA
ID: 7123310
You can try the -n option:

sftp -n wsadmin@uscscdev7 webuser@webhost <<EOF
...etc...
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 150 total points
ID: 7124044
sh does not allow to read password from STDIN (batch file, here document, or whatever) for obvious reason.
You need to setup sh with a RSA or DSA key which has a blank password
AFAIK sftp has no -i option to specify the key-file, so you're forced to use the default ones, ~/.ssh/identity for example.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7124046
oops, typo:
please substitute all words sh by ssh
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 9

Expert Comment

by:PeterMac
ID: 7126856
Havn't tried with SFTP, but following works with most FTP systems. Needs -n on command line to allow manual login. Insert at start of batch file :-

user "USERNAME"
"PASSWD"

Alternatively should be possible to setup SFTP to run with "anonymous" access permitted. Will not then require entry of username, password at all.
0
 
LVL 14

Expert Comment

by:chris_calabrese
ID: 7127074
SFTP is a very different beast from FTP.  Ahoffman's comments are right-on.
0
 

Expert Comment

by:SoHo
ID: 7319941
why don't you use ssh keys.
0
 

Expert Comment

by:SoHo
ID: 7319945
ahoffman already gave that answer, duh.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question