public static void DownloadFile(string ftpURL, string UserName, string Password, string ftpDirectory, string FileName, string LocalDirectory) { try { FtpWebRequest requestFileDownload = (FtpWebRequest)WebRequest.Create(ftpURL + "/" + ftpDirectory + "/" + FileName); requestFileDownload.Credentials = new NetworkCredential(UserName, Password); requestFileDownload.Method = WebRequestMethods.Ftp.DownloadFile; FtpWebResponse responseFileDownload = (FtpWebResponse)requestFileDownload.GetResponse(); Stream responseStream = responseFileDownload.GetResponseStream(); FileStream writeStream = new FileStream(LocalDirectory + "/" + FileName, FileMode.Create); int Length = 2048; Byte[] buffer = new Byte[Length]; int bytesRead = responseStream.Read(buffer, 0, Length); while (bytesRead > 0) { writeStream.Write(buffer, 0, bytesRead); bytesRead = responseStream.Read(buffer, 0, Length); } responseStream.Close(); writeStream.Close(); requestFileDownload = null; } catch (Exception ex) { string error = ex.ToString(); Loghandling.Logerror(error); Application.Exit(); } Filecheck(); }
public static void DownloadUpdate(string ftpURL, string UserName, string Password, string ftpDirectory, string ftpupdateDirectory, string updateFile, string LocalDirectory) { Form1.flag = true; Form1.Form1_Load1(); try { FtpWebRequest requestFileDownload = (FtpWebRequest)WebRequest.Create(ftpURL + "/" + ftpDirectory + "/" + ftpupdateDirectory + "/" + updateFile); requestFileDownload.Credentials = new NetworkCredential(UserName, Password); requestFileDownload.Method = WebRequestMethods.Ftp.DownloadFile; FtpWebResponse responseFileDownload = (FtpWebResponse)requestFileDownload.GetResponse(); Stream responseStream = responseFileDownload.GetResponseStream(); FileStream writeStream = new FileStream(LocalDirectory + "/" + updateFile, FileMode.Create); int Length = 2048; Byte[] buffer = new Byte[Length]; int bytesRead = responseStream.Read(buffer, 0, Length); while (bytesRead > 0) { writeStream.Write(buffer, 0, bytesRead); bytesRead = responseStream.Read(buffer, 0, Length); } responseStream.Close(); writeStream.Close(); requestFileDownload = null; Form1.flag = false; } catch (Exception ex) { string error = ex.ToString(); Loghandling.Logerror(error); return; } Process.Start("TSR-VTC.exe"); try { Form1.Form1_Load1(); Process.Start("cmd.exe", "/c taskkill /F /IM tsrvtgui.exe"); Application.Exit(); } catch (Exception ex) { string error = ex.ToString(); Loghandling.Logerror(error); return; } }
public static void Regcheck() { using (var hklm = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64)) using (var key = hklm.OpenSubKey(@"SOFTWARE\TSR-VTC\TSR-VTC_Launcher")) { if (key != null) { currentversion = (string)key.GetValue("Version"); if (currentversion != null) { if (currentversion == expectedversion) { string error = "Same Version Installed!"; Loghandling.Logerror(error); Application.Exit(); } else { string exeFile = (new Uri(Assembly.GetEntryAssembly().CodeBase)).AbsolutePath; string updatecheckfile = Path.GetDirectoryName(exeFile); string _LocalDirectory = updatecheckfile; //Local directory where the files will be downloaded DownloadUpdate(_ftpURL, _UserName, _Password, _ftpDirectory, _ftpupdateDirectory, _updateFile, _LocalDirectory); } } } else { string exeFile = (new Uri(Assembly.GetEntryAssembly().CodeBase)).AbsolutePath; string updatecheckfile = Path.GetDirectoryName(exeFile); string _LocalDirectory = updatecheckfile; //Local directory where the files will be downloaded DownloadUpdate(_ftpURL, _UserName, _Password, _ftpDirectory, _ftpupdateDirectory, _updateFile, _LocalDirectory); } } }