ftp batch file in C# app

Jun 7 2007 4:43 PM
I am having some issues with this code. It creates the batch file when executed. The batch file will run outside of the app, however the ftp process fails when I run the batch file through the app.

I appreciate any input tremendously as I have wasted too much company time on a small issue for one day.

code follows:

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);
     }
}

edit: This problem has since been solved. The issue was that this line  sw.WriteLine("ftp -n -s:trackerBat.txt"); " was referencing a relative and not absolute path. By assigning "c:\\programs\\tracker\\trackerBat.txt" the path was recognized and the batch file executed.