Solved

SFTP - passing a password from within a script

Posted on 2002-07-01
7
24,472 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
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.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

705 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