I have written a winform app in C# which modifies FTP commands in a script file (server address etc..) and then executes a batch file that is supposed to start FTP from command prompt and download files according to script.
When i run the Batch file external to app (from command prompt or double click), the files are being downloaded fine, but when executing the batch from the app nothing happens...
I also noticed following difference: When running batch externally I see "ftp> open 10.1.1.1" in cmd window. When running batch from the app I see "open 10.1.1.1" in cmd window,(missing the "ftp>").
My guess is that I'm not using System.Diagnostics.Process() correctly...
C# relevant part:
private void button1_Click(object sender, EventArgs e)
{
var cmd = new System.Diagnostics.Process();
cmd.StartInfo.FileName = "runFTP.bat";
cmd.StartInfo.UseShellExecute = false;
cmd.StartInfo.RedirectStandardInput = true;
cmd.StartInfo.WorkingDirectory = path;
cmd.Start();
cmd.WaitForExit();
cmd.Close();
}
}
Batch file (runFTP.bat):
echo off
@echo Downloading files...
REM ==Start FTP with script==
ftp -i -s:ftpCmd.txt
del ftpCmd.txt
@echo Done!
@echo Exiting...
FTP script file (ftpCmd.txt):
open 10.1.1.1
user
password
bin
cd /rootFolder/new
lcd C:\Downloads
mget *.*
bye
ftpoutput to a file in both scenarios and share the output here?