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 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
10,786 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,403 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Rich Matheisen 45,111 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 32,246 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. 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