Click here to Skip to main content
15,895,192 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need to transfer multiple files from a remote server to local machine.

I have then scheduled winscp.exe with argument "/console/script=D:\sync.txt"
sync.txt file contains the following commands.

option batch on
option confirm off
open username@hostname
cd folderContainingFiles
option transfer binary
get /desiredFile.extension pathInLocalComputer
exit

When I am running the task, winscp window is opening but it is not logging in.

Any help anyone?

What I have tried:

option batch on
option confirm off
open username@hostname
cd folderContainingFiles
option transfer binary
get /desiredFile.extension pathInLocalComputer
exit
Posted
Updated 9-Jun-16 1:36am
v3

 
Share this answer
 
Hey,

I did by creating batch file on the run and then opening cmd application and then running it.

Here is my code if it helps anyone:

C#
//creating batch file
            StreamWriter sw = new StreamWriter(@"C:\\file_transfer.bat");
 
            sw.WriteLine("open username:password@host");
            sw.WriteLine("option transfer binary");
            sw.WriteLine("cd /mainFolder/subFolder");
            sw.WriteLine("get file.extension C:\\pathWhereYouWantToPutIt\\");
            sw.WriteLine("get *.extension C:\\pathWhereYouWantToPutIt\\");
//second get for multiple files
            sw.WriteLine("exit");
            sw.Close();



C#
//file transfer
            Process p = new Process();
            p.StartInfo.FileName = "cmd.exe";
            p.StartInfo.WorkingDirectory = @"C:\\Windows\\System32";
            p.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.Start();

            p.StandardInput.WriteLine(@"cd C:\\If-You-Want-To-Go-To-Another-Directory");
            p.StandardInput.WriteLine("WinSCP.com /script=\"C:\\file_transfer.bat");
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900