DOS batch file: SSH connection, how to script to enter password when prompted?

Posted on 2004-08-26
Last Modified: 2007-12-19
I need to create a batch file on a Windows 2000 box which connects to linux box running an ssh (and ftp) server and uploads files in continuous loop for testing our connection.

I'm using putty's pscp to connect to transfer the files over. The problem is there is no way to specify the password on the pscp commandline. So I need to simulate its entry in the batch file as I can't have the user entering it manually everytime. This batch file isn't meant to be secure so yes the actual password will be exposed in the batch file. How can I do this? Here's what I have so far:

pscp -r C:\data userName@
REM enter password when prompted

Thanks for any help!
Question by:patKC

Expert Comment

ID: 11900521
This .vbs script will do it for you, save the below script to .vbs, ammend your details for domain\username and password, and the file name of course. See below link to my previously accepted answer.


Dim WshShell, scomputername
Set WshShell = WScript.CreateObject("WScript.Shell")
Set oNetwork = WScript.CreateObject( "WScript.Network" )

srunme = "runas /userName@ pscp -r C:\data"

WshShell.Run srunme
WScript.Sleep 500
WshShell.Sendkeys "password" & chr(13)

LVL 11

Expert Comment

ID: 11900778
Or you can create certificates and use certificate authentication instead of password authentication.
See "man ssh-keygen" on your link box

Expert Comment

ID: 11900905
create a key without a password. You can load this key in a batch it is still safer than a password included into a batch.
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.


Expert Comment

ID: 11901227

PuTTY 0.52 (and late)r have a -pw command line switch, a la:

pscp -pw password -r C:\data userName@

If that doesn;t work for you, try:

echo password | pscp -r C:\data userName@
LVL 34

Expert Comment

ID: 11907048
Yeah, I wouldn't bother with a password. Just generate a unique key to thw workstation and have SSH go straight in. Lot simpler.

Expert Comment

ID: 11908721
If cgwilder's last suggestion doesn't work, create a text file with the password in and run the command like this:

pscp -r C:\data userName@ <password.txt
LVL 34

Expert Comment

ID: 12030759
LVL 34

Expert Comment

ID: 13676189
Fine by me

Accepted Solution

modulo earned 0 total points
ID: 13692566
PAQed with no points refunded (of 125)

Community Support Moderator

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Title # Comments Views Activity
Windows update on Win 7 Home prem. 17 96
Comments on the use of ftp server/client on OS/400 AS/400 4 111
PXE question 7 85
Windows Server 2016 Failover Cluster Question 3 76
Introduction Often we come across situations wherein our batch files would be needing to reboot Windows for a variety of reasons. A few of them would be like: (1) Setup files have been updated whose changes can take effect only after a reboot …
Hello I read in a discussion about a person who configured a very simple mirror RAID with two hard drives; the system and data were on the same partition. He asked how to repair the system as it was not booting up anymore. In his case running …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

821 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