Password automatic entry command for pscp

I want to copy some file to a remote Linux system from my Windows PC using pscp (from putty). I wrote a small script that calls pscp commands as follows:

 "C:\Users\hp\Desktop\pscp.exe" -scp C:\Users\hp\Desktop\scripts\* root@192.168.1.177 :/root/scripts "C:\Users\hp\Desktop\pscp.exe" -scp C:\Users\hp\Desktop\scripts2\* root@192.168.1.177 :/root/scripts2 pause 

But when I run this bat script, I am asked to enter a password, so I entered the password manually.

Is there a way to automatically enter a password through a batch file?

+6
source share
5 answers

From putty documentation

5.2.2.6 -pw passw login with the specified password

If a password is required to connect to the host, PSCP will interactively offer you this. However, this may not always be appropriate. If you use PSCP as part of some automated task, it is not possible to enter the password manually. The -pw option for PSCP allows you to specify a password for use on the command line.

+16
source
 pscp -pw yourPasswordHere C:\Users\testUser\Downloads\test.sh testUser@123.123.123.123 :/home/testUser 

I noticed that no one sent a sample of this command with the -pw option.

+11
source

You can use this material for yourself. Use the /? to see help. The relevant parts are given below.

  > pscp /?
 PuTTY Secure Copy client
 Release 0.60
 Usage: pscp [options] [ user@ ] host: source target
        pscp [options] source [source ...] [ user@ ] host: target
        pscp [options] -ls [ user@ ] host: filespec
 Options:
 ......
   -l user connect with specified username
   -pw passw login with specified password
 ......

Use the -l and -pw options to specify a user and password.

So, while this answers the question you asked, the real opportunity for you is to learn how to get documentation from command line utilities.

+3
source

Use putty to configure remote login without password. This will include the puttygen command. You will need the private key, and the target will need to use the public key. After you confirm that you have a good private key file and login without entering a password, you can refer to it using the "-i" private key option on pscp. You may be able to configure the key without putty connection if this is not permitted, but this is the easiest way. Just say no to passwords in a clear way:

 C:\Users\riglerjo>pscp -i .ssh\rigler_rsa.ppk test.txt rigler@rigler.org :. test.txt | 0 kB | 0.0 kB/s | ETA: 00:00:00 | 100% 
0
source
 sshpass -p'password' pscp -A -H "ip" -t 20 -l root /var/www/html/temp_santosh.txt /tmp/ 

You can use sshpass with the -p option just before pscp

0
source

All Articles