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

Prasanna Sekar 1 Reputation point
2020-08-04T18:57:14.917+00:00

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 @Ana Paula de Paula

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

pwd

cd /root/csvfiles

get *.csv c:\data

Can someone please help

Windows for business Windows Server User experience PowerShell
Windows for business Windows Client for IT Pros User experience Other
{count} votes

3 answers

Sort by: Most helpful
  1. Rich Matheisen 47,901 Reputation points
    2020-08-04T21:28:02.107+00:00

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

    Posh-SSH

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

    1 person found this answer helpful.
    0 comments No comments

  2. MotoX80 36,291 Reputation points
    2020-08-04T23:44:37.823+00:00

    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

    0 comments No comments

  3. Young Yang (Shanghai Wicresoft Co,.Ltd.) 661 Reputation points
    2020-08-20T01:46:22.297+00:00

    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.
    :)

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.