I am following the example at https://winscp.net/eng/docs/scripting to automate the transfer of files from my PC to an SFTP server. However each time I try to provide a password for private key, it fails to authenticate.

I am able to use the same password when using the WinSCP graphical user interface and when I explicitly type the password in the command line however not when I automate.

My code looks as follows

open sftp://user:password%21@example.com

I have followed the suggestion at https://winscp.net/eng/docs/session_url to encode special characters hence the %21 which symbolizes an exclamation mark. Interestingly enough the example on the page does not encode the exclamation mark e.g. 4pRte!ai%253@example.com

I have also tried using password! and that doesn't work either.


The issue was that it was expecting a password phrase for a private key which WinSCP doesn't support providing programmatically as per the FAQ at https://winscp.net/eng/docs/faq_passphrase.

The way around it was to use the Pageant agent that is provided with the WinSCP installation or as a standalone executable at https://winscp.net/eng/download.php. Hopefully this helps someone else in the future.


It's not "password", it's "passphrase".

As per WinSCP FAQ How can I connect without entering private key passphrase each time?:

Automating Private Key Authentication
You can specify the passphrase using -passphrase switch of open command in scripting


open -passphrase=... -privatekey=... sftp://user@example.com/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.