question

PrasannaSekar-0647 avatar image
0 Votes"
PrasannaSekar-0647 asked saldana-msft edited

How to get file from SFTP to local directory using bat file

Hi ,

I'm trying to get file from SFTP folder to my windows local directory .

I'm able to access SFTP via Winscp tools & move the file to my local using sftp & get command



However when i try to automate it using bat file , it is not working .Bat file runs & nothing happens.

Script in getcsvfile.bat file
echo @off

open sftp://Username:pwd@publicIP/ -hostkey="ssh-rsa 2048 key="

pwd

cd /root/csvfiles

get *.csv c:\data

Can someone please help

windows-10-generalwindows-server-powershell
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

You should read the documentation for sftp to make sure you have everything.
Found this but a bit old: https://www.computerworld.com/article/2928599/how-to-automate-sftp-file-transfers-in-microsoft-windows.html


0 Votes 0 ·
RichMatheisen-8856 avatar image
1 Vote"
RichMatheisen-8856 answered

Why use a batch file? Use PowerShell and the POSH-SSH module.

Posh-SSH


If you'd prefer something else try WinSftp
index.php



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

MotoX80 avatar image
0 Votes"
MotoX80 answered

A bat/cmd file runs Windows commands. The open/pwd/cd/get commands are not Windows commands, they are Winscp commands. Put those commands in a different file and call Winscp in your bat file passing that command sequence as an argument.

how-to-execute-winscp-commands-from-a-batch-file


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

YoungYang-MSFT avatar image
0 Votes"
YoungYang-MSFT answered

Hi, given that this post has been quiet for a while, this is a quick question and answer. Has your question been solved? If so, please mark it as an answer so that users with the same question can find and get help.
:)

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.