I appreciate any input tremendously as I have wasted too much company time on a small issue for one day.
code follows:
C#
private void btnStartFtp_Click(object sender, EventArgs e)
{
System.DateTime date = System.DateTime.Now;BatFile = new FileInfo ( @"c:\programs\tracker\trackerBat.bat");
TextFile = new FileInfo(@"c:\programs\tracker\trackerBat.txt");
try
{
/*********************************************************************
* Create text file which the following batch file will utilize.
********************************************************************/
using (StreamWriter sw = TextFile.CreateText())
{
sw.WriteLine("open " + ipAddress);
//sw.WriteLine("pause");
sw.WriteLine("user");
sw.WriteLine(login);
//sw.WriteLine("pause");
sw.WriteLine(password);
//sw.WriteLine("pause");
sw.WriteLine(filePath);
for (int x = 1; x < 4; x++)
{
sw.WriteLine("get pVQI" + date.ToString("MMdd") + x + ".zip");
//sw.WriteLine("pause");
}
sw.WriteLine("quit");
sw.Close();
}
/*********************************************************************
* Create batch file to download files.
********************************************************************/
using (StreamWriter sw = BatFile.CreateText())
{
sw.WriteLine("@echo off");
sw.WriteLine("pause");
sw.WriteLine("prompt $");
sw.WriteLine("pause");
sw.WriteLine("ftp -n -s:trackerBat.txt");
sw.WriteLine("pause");
sw.Close();
}
/*********************************************************************
* Run batch file to download via ftp.
********************************************************************/
ProcessStartInfo psi = new ProcessStartInfo(@"c:\programs\tracker\trackerBat.bat");
psi.RedirectStandardOutput = false;
psi.WindowStyle = ProcessWindowStyle.Normal;
psi.UseShellExecute = false;
Process ftp = Process.Start(psi);
StreamReader output = ftp.StandardOutput;
ftp.WaitForExit();
if (ftp.HasExited)
{
rtbOutput.AppendText("process ended\n");
string line;
while (!output.EndOfStream)
{
line = output.ReadLine();
rtbOutput.AppendText(line + "\n");
}
}
else
{ }
}
catch (Exception error)
{
rtbOutput.AppendText(error.Message);
}
}
Answers
Know the answer? Post it. Somebody with the same question will find it here.