0

the task at hand is to have windows batch script, that can connect to an SFTP server, scan certain folders for presence of any file in them. If the file is there, copy it to local machine.

If possible, i would want to avoid installing any external tools, such as WinSCP (however,i would welcome any such suggestions).

I am new to batch scripting (as in i started looking into it today), and would help with suggestions and pointers that i can look into more detail.

For now i am stuck at first step - connecting to an SFTP server

I can do it via command line by typing

sftp <username>@hostname

and enter password when prompted.

But how do i provide password when running a batch script? I want the connection process to be automatic, as soon as batch script runs.

I saw some comments about installing sshpass and then using

sshpass -p YOUR_PASSWORD sftp -oBatchMode=no -b YOUR_COMMAND_FILE_PATH USER@HOST

But other posts called it very un-secure.

I welcome any comments, suggestions, links to read to hep me with this first step. Feel free to post your suggestions on other steps (such as scanning specific folders for a file, etc).

Given i have only few days to accomplish this, i thought i would get pointers at stackexchange, instead of going through whole tutorials and then think about a solution. So if you guys have any ideas, and comments on their pros/cons, i welcome it.

user2957592
  • 183
  • 1
  • 5
  • This question already has an answer [here](https://stackoverflow.com/questions/16150152/secure-ftp-using-windows-batch-script) – Konstantin Baklaev Sep 12 '19 at 18:09
  • @KonstantinBaklaev Yes i read that one. As mentioned earlier, i would prefer to avoid installing WinSCP. – user2957592 Sep 12 '19 at 18:58
  • You might be able to use `echo password | sftp username@hostname`, but I can't test that right now which is why it's a comment instead of an answer. – SomethingDark Sep 12 '19 at 21:58

0 Answers0