Question

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 call the pscp commands in this way:

"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 launch this bat script, I'm asked to input the password, so I input the password manually.

Is there a way to input the password automatically through the batch file?

Was it helpful?

Solution 2

From putty documentation

5.2.2.6 -pw passw login with specified password

If a password is required to connect to the host, PSCP will interactively prompt you for it. However, this may not always be appropriate. If you are running PSCP as part of some automated job, it will not be possible to enter a password by hand. The -pw option to PSCP lets you specify the password to use on the command line.

OTHER TIPS

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

I've noticed that no one posted sample of that command with -pw option.

You can work this stuff out for yourself. Use the /? option to see the help. The pertinent parts are included 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 whilst that answers the specific question that you asked, the real opportunity for you is to learn how to obtain documentation from command line utilities.

Use putty to set up a remote login without a password. This will involve the puttygen command. You will need a private key and the target will need a public key. Once you verified that you have a good private key file and login without typing a password, you can reference it with the "-i" private key option on pscp. You might be able to set up the key without the putty connect if it isn't allowed, but this is the easiest way. Just say no to passwords in the clear:

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%

If your coping a local file to remote directory use:

pscp -pw yourPasswordHere C:\Users\testUser\Downloads\test.sh testUser@10.10.10.10:/home/testUser

If your coping a remote file to local directory use:

pscp -pr yourPasswordHere testUser@10.10.10.10:/home/testUser/test.sh C:\Users\testUser\Downloads\
$ pscp -pw "speci4l^()Ch4rs" -r -sftp C:/Users/username/code/scp/* username@example.com:/var/www/example.com/public_html/scp

Windows 11, using MINGW64 (Git bash), use double quotes for the password.

  • -pw Password
  • -r Recursive
  • -sftp Force encrypted transfer

Order can be important.

sshpass -p'password' pscp -A -H "ip" -t 20 -l root /var/www/html/temp_santosh.txt /tmp/

You can use sshpass with -p option just before pscp

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top