示例#1
0
 public static bool FTP_Download(string _url, string _file, ref MessageWait w)
 {
     CheckPaths("c:\\drivers\\");
     try
     {
         FtpWebRequest ftpWebRequest = (FtpWebRequest)WebRequest.Create(_url);
         ftpWebRequest.Method      = "RETR";
         ftpWebRequest.Credentials = new NetworkCredential("install", (string)null);
         ftpWebRequest.UsePassive  = true;
         ftpWebRequest.UseBinary   = true;
         ftpWebRequest.KeepAlive   = false;
         Stream responseStream = ftpWebRequest.GetResponse().GetResponseStream();
         if (File.Exists("c:\\drivers\\" + _file))
         {
             try
             {
                 File.Delete("c:\\drivers\\" + _file);
             }
             catch (Exception ex)
             {
                 MessageBox.Show("FTP DELETE ERROR: " + ex.Message + " [" + _file + "]");
                 return(false);
             }
         }
         BinaryWriter binaryWriter = new BinaryWriter(File.Open("c:\\drivers\\" + _file, FileMode.CreateNew));
         int          num          = 0;
         int          num2         = 0;
         byte[]       array        = new byte[1024];
         do
         {
             num = 0;
             try
             {
                 num = responseStream.Read(array, 0, array.Length);
             }
             catch
             {
             }
             if (num > 0)
             {
                 num2 += num;
                 binaryWriter.Write(array, 0, num);
                 w.UpdateInfo(num2);
             }
             Application.DoEvents();
         }while (num != 0);
         binaryWriter.Flush();
         binaryWriter.Close();
     }
     catch (Exception ex2)
     {
         MessageBox.Show("FTP ERROR: " + ex2.Message + " [" + _file + "]");
         return(false);
     }
     return(true);
 }
示例#2
0
        private void bUPDATE_Click(object sender, EventArgs e)
        {
            MessageWait w = new MessageWait("Download drivers");

            w.UpdateInfo(-2);
            w.Show();
            for (int i = 0; i < 10; i++)
            {
                Application.DoEvents();
                Thread.Sleep(200);
            }
            for (int j = 0; j < list_drv.Length; j += 2)
            {
                w.UpdateMSG("Download " + list_drv[j]);
                FTP_Download("ftp://ftp.jogarvip.com/" + list_drv[j + 1], list_drv[j + 1], ref w);
            }
            w.Close();
            MessageBox.Show("Drivers downloades. Stored in 'c:\\drivers'");
        }