2

I need to connect to our SFTP Server using the built in windows sftp feature and a .bat file which automatically inputs the login data, user and pw. I´ve tried everything and just cant figure out the correct way. No matter what I try, it always asks me to manually put in my password. I want to avoid that. It should do the whole SFTP process by itself once it runs.

One thing i tried was this:

sftp sftp://USERXYZ:PASSWORDXYZ@myftp.COMPANY.com

But this still asks me to manually put in my pw and to make it worse, it thinks the user is "USERXYZ:PASSWORDXYZ" instead of just "USERXYZ"

Here´s my script with dummy values:

sftp sftp://USER@myftp.COMPANY.com
lcd C:\Users\PATHXYZ
cd PATHXYZ
put TESTFILE.txt
bye

Hope you can help me, thanks in advance.

Bangarus
  • 21
  • 1
  • 2
  • 1
    It is not allowed... and for good reason, Security. If you ran the password from command line, the password would be accessible if you interrogate the running services/processes. – Gerhard Nov 12 '19 at 07:59

1 Answers1

2

OpenSSH sftp does not have an option to provide a password for security reasons. It does not even accept an sftp:// URL.

There are lot of workarounds and hacks used for Linux version:
How to run the sftp command with a password from Bash script?
I'm not sure if there's a commonly used workaround/hack for Windows version.

Though you should not use a workaround/hack. It is better to use a public key authentication instead of a password authentication.
See How to properly configure Win32-OpenSSH authentication.


Or use another SFTP client that offers an option to provide a password. For example (my) WinSCP client accepts the sftp:// URL which you have tried to use. There is a guide for converting OpenSSH sftp script to WinSCP.

Martin Prikryl
  • 167,268
  • 50
  • 405
  • 846
  • 2
    Correct! Windows 10 comes with OpenSSH built in, so with some knowledge you can setup ssh keys for sftp only. – Gerhard Nov 12 '19 at 08:02