Solved

SFTP - passing a password from within a script

Posted on 2002-07-01
7
22,846 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
forget admin password 8 23
Unable to connect to AIX server using putty 23 791
AIX 5.3 group password policy changes 7 22
MarkLogic 1 48
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ā€¦
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consolā€¦
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.

708 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now