1

I am trying to set up a batch file for an automated transaction, however my tests have so far failed.

I have the public key of the server where the connection is made. It has been saved as a .pkk file and imported into WinSCP.

I have logged the results in text file, and this reads as below:

Username: 4m4nseth (Password: No, Key File: No)

The key file is there but WinSCP for some reason doesn't pick it up.

If running as a batch file I get the following message:


Session name: 4m4nseth@IP Address Host name: IP Address (Port: 22) User name: 4m4nseth (Password: No, Key file: No) Tunnel: No Transfer Protocol: SFTP (SCP) Ping type: -, Ping interval: 30 sec; Timeout: 15 sec

But the following if running in the WinSCP


Session name: 4m4nseth@ipaddress Host name: ipaddress (Port: 22) User name: 4m4nseth (Password: No, Key file: Yes) Tunnel: No Transfer Protocol: SFTP (SCP)

As you can see the key file is saved but when running as batch command it does not recognize.

1 Answer 1

1

I believe you have the public key and private key the wrong way around.

If you are using WinSCP to copy information to (or from) a server, you need to generate a public/private key on the box running WinSCP, configure WinSCP with the private key and put the public key in the appropriate place on the server (In Linux in ~username/.ssh/authorized_keys

While this seemed counterintuitive to me at first (a long time ago !!) it actually makes perfect sense if you work through the logic. Thinking about it as follows may help -

  1. A private key is supposed to be private, ie only something you should know.
  2. If the server belongs to someone else, you don't wan to be giving them something only
    you should know so you don't want to give them your private key.
  3. On the other hand, if you give them your public key, and there system is compromised and someone else adds your public key to their setup, that only means you can access their system, you have not lost anything. If on the other hand you had had to give them your private key you loose control over it.
1
  • Hi Thanks. I have figured out (from this forum) that winSCP does not support automation at all. I used pageant to hold the Public key and now it can authenticate and create a session. However, I am getting the following error:Reading Remote Directory: Error changing directory to '/script=E:\Data\GmousCR12\bin\Get.sftp' Cannot get real path for '/script=E:\Data\GmousCR12\bin\Get.sftp' No such file or directory. Error code. 2 Error message from Server: No Such file Request code: 16 Session started. Active Session: [1] username@ipaddress The file exist on another E drive of the same server.
    – Aman
    Feb 8, 2013 at 13:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .