samedi 9 mai 2015

Remote file transfer (directory specific) via matlab & winscp batch file

I have to transfer files remotely, which are in different directories. The directories are synchronized with google drive & every day there are new additions. I want to run a script that works once a day & will transfer the directories those are new. I can handle the part of selecting new directories. I am using Matlab for these directory operations. For transferring files, I have written a windows bat file which calls another WinSCP script (bat file) that performs the transfer. Upto this point there is no problem.

My question is that, when I am calling the windows bat file from Matlab, I want to do that for specific directory. For example, my directory names are dir_1, dir_2, etc. & I want to be specific with the directory number. More specifically, I want to call the bat file with an argument integer specifying the directory name. From that bat file, when I call another WinSCP bat file, I want to pass that as a parameter too to transfer the specific directory.

Let`s give an example:

From Matlab I am calling:

dos(`PathToBatFile.bat`)

The bat file contains (which calls Winscp):

cd C:\winscp

WinSCP.com /script="test.bat"

test.bat contains (which does the actual transfer):

open sftp://uname:pass@webaddress.com/ -hostkey="ssh-rsa 2048 xx:xx:xx"

put D:\mydrive\file_1.txt   /home/user/

close

exit

So, in these scripts I am transferring file_1.txt to a remote location. I want to do it for specific directory, the name of which I can get from Matlab (the dos() command in Matlab runs in a loop where I get the directory number).

Aucun commentaire:

Enregistrer un commentaire