Thursday, June 23, 2016

How to configure a batch file to make use of winscp to get files from remote server

I have a perl script scheduled in each databases box that will do the health-checks of my databases. Every morning it will generate a html file and I would like to fetch all those files in a single click into  my local machine  . How to do that ? As ftp is disabled in my database box , I have to rely on scp . I could able to fetch all the files by creating a batch file .

Note:-   Winscp is  required for this set up and it should be installed in your local machine. I have installed my WinScp software in "C:\Program Files (x86)\WinSCP" .

Create a batch file say for example
Get_files_using_winscp.bat  with following contents

@echo off

del "C:\Users\mahesh\Desktop\DB_HealthCheck\Report\*.html"
cd "C:\Program Files (x86)\WinSCP"
Winscp.com /script=C:\Users\mahesh\Desktop\DB_HealthCheck\get_my_files.txt
Exit 

And the contents of  get_my_files.txt is given below 

option echo off

option batch on

option confirm off

open sftp://oracle:Welcome123@10.18.211.8

lcd "C:\Users\mahesh\Desktop\DB_HealthCheck\Report"

cd  /home/oracle/HealthChecks/html/

get -nopermissions -nopreservetime DBHealthChecks_*


open sftp://oracle:Welcome123@10.18.214.9
lcd "C:\Users\mahesh\Desktop\DB_HealthCheck\Report"

cd  /home/oracle/HealthChecks/html/

get -nopermissions -nopreservetime DBHealthChecks_*

Double click the batch file you created and you will get your files in your local PC.

Enjoy :)

No comments:

Post a Comment