/// <summary> /// 同步下载文件 /// </summary> /// <param name="localFileName"></param> /// <param name="remoteFileName"></param> /// <param name="resume">如果本地文件存在,是否续传</param> public void Download(string localFileName, string remoteFileName, bool resume) { string path = Path.GetDirectoryName(localFileName); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } if (File.Exists(localFileName) && FileUsing(localFileName)) { throw new Exception("本地文件 " + localFileName + " 被占用。"); } if (resume) { m_pFtp.ResumeNextTransfer(); m_pFtp.DownloadFile(localFileName, remoteFileName); m_pFtp.CancelResume(); } else { m_pFtp.CancelResume(); m_pFtp.DownloadFile(localFileName, remoteFileName); } }
public static void Check(ref FTPConnection ftpcon) { try { // return if disabled if ((Config.settings.MinecraftVersion == "") || (Config.settings.MinecraftDownloadFile == "")) { return; } // ok when launcher is there if (File.Exists(Locations.Launcher_Install) || File.Exists(Locations.Launcher_Download)) { Console.WriteLine(Strings.Get("MinecraftOK")); return; } // download launcher if (!Directory.Exists(Locations.LocalFolderName_Launcher)) { Directory.CreateDirectory(Locations.LocalFolderName_Launcher); } Console.WriteLine(Strings.Get("MinecraftDownload")); ftpcon.DownloadFile(Locations.Launcher_Download, Config.ftpsettings.FtpServerFolder + "/" + Config.settings.MinecraftDownloadFile); } catch (Exception ex) { Console.WriteLine(Strings.Get("MinecraftError") + ex.Message); Console.WriteLine(Strings.Get("PressKey")); Console.ReadKey(); Program.Exit(false); } }
// downloads modsync.xml public static void FtpUpdate(ref FTPConnection ftpcon) { string ConfigFile = "modsync.xml"; string LocalFile = Locations.LocalFolderName_Minecraft + "\\" + ConfigFile; string RemoteFile = ftpsettings.FtpServerFolder + "/" + ConfigFile; try { if (ftpcon.Exists(RemoteFile)) { ftpcon.DownloadFile(LocalFile, RemoteFile); settings = (Settings)Read(typeof(Settings), LocalFile); } else { Console.WriteLine(Strings.Get("ConfigMissing")); } } catch (Exception ex) { Console.WriteLine(Strings.Get("ConfigError") + ex.Message); Console.WriteLine(Strings.Get("PressKey")); Console.ReadKey(); } }
// updates single executable public static void ExecutableUpdate(ref FTPConnection ftpcon) { // return if clickonce deployed if (ApplicationDeployment.IsNetworkDeployed) { return; } // return if disabled if (Config.settings.ToolVersion == "") { return; } // get location and version Assembly file = Assembly.GetExecutingAssembly(); string file_location = file.Location; string file_version = FileVersionInfo.GetVersionInfo(file_location).FileVersion; int curversion, newversion; if (int.TryParse(file_version.Replace(".", ""), out curversion) && int.TryParse(Config.settings.ToolVersion.Replace(".", ""), out newversion)) { // update if newer available if (curversion < newversion) { string LocalFile = Locations.LocalFolderName_Minecraft + "\\" + Config.settings.ToolDownloadFile; string RemoteFile = Config.ftpsettings.FtpServerFolder + "/" + Config.settings.ToolDownloadFile; try { // download new file Console.WriteLine(Strings.Get("AutoUpdate")); ftpcon.DownloadFile(LocalFile, RemoteFile); // start a process with a delayed file copy Process process = new Process(); ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.WindowStyle = ProcessWindowStyle.Normal; startInfo.FileName = "cmd.exe"; startInfo.Arguments = "/C ping 127.0.0.1 -n 1 -w 5000 > nul & copy /Y " + LocalFile + " " + file_location + " & " + file_location; process.StartInfo = startInfo; process.Start(); Program.Exit(false); } catch (Exception ex) { Console.WriteLine(Strings.Get("AutoUpdateError") + " " + ex.Message); Console.ReadKey(); } } } }
static void Install(ref FTPConnection ftpcon) { // create default profile if missing if (!File.Exists(Locations.LauncherProfiles)) { UpdateProfile("(Default)", Config.settings.MinecraftVersion); } string LocalFile = Locations.LocalFolderName_TempDir + "\\" + Config.settings.ForgeDownloadFile; string RemoteFile = Config.ftpsettings.FtpServerFolder + "/" + Config.settings.ForgeDownloadFile; try { // download and install forge Console.WriteLine(Strings.Get("ForgeDownload")); File.Delete(LocalFile); ftpcon.DownloadFile(LocalFile, RemoteFile); Console.WriteLine(Strings.Get("ForgeInstall")); if (File.Exists(Locations.Java)) { // extract wrapper class to invoke client install Resources.ExtractFile(Locations.LocalFolderName_TempDir, "ForgeInstallWrapper.class"); ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = Locations.Java; psi.WorkingDirectory = Path.GetDirectoryName(LocalFile); psi.Arguments = "-cp \"" + Locations.LocalFolderName_TempDir + "\" ForgeInstallWrapper \"" + Config.settings.ForgeDownloadFile + "\" \"" + Locations.LocalFolderName_Minecraft + "\""; psi.UseShellExecute = false; var process = Process.Start(psi); process.WaitForExit(); File.Delete(LocalFile); File.Delete(Locations.LocalFolderName_TempDir + "\\" + "ForgeInstallWrapper.class"); } else { Process.Start(LocalFile); // exit without starting game Program.Exit(false); } } catch (Exception ex) { Console.WriteLine(Strings.Get("ForgeError") + ex.Message); Console.WriteLine(Strings.Get("PressKey")); Console.ReadKey(); Program.Exit(true); } }
public static void Check(ref FTPConnection ftpcon) { // return if disabled if ((Config.settings.JavaVersion == "") || (Config.settings.JavaDownloadFile == "")) { return; } // check registery key RegistryKey subKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\JavaSoft\\Java Runtime Environment\\" + Config.settings.JavaVersion); if (subKey != null) { Locations.Javaw = subKey.GetValue("JavaHome").ToString() + "\\bin\\javaw.exe"; Locations.Java = subKey.GetValue("JavaHome").ToString() + "\\bin\\java.exe"; Console.WriteLine(Strings.Get("JavaOK")); return; } Console.WriteLine(Strings.Get("JavaNotFound") + Config.settings.JavaVersion); string LocalFile = Locations.LocalFolderName_TempDir + "\\" + Config.settings.JavaDownloadFile; string RemoteFile = Config.ftpsettings.FtpServerFolder + "/" + Config.settings.JavaDownloadFile; try { // download and install java Console.WriteLine(Strings.Get("JavaDownload")); File.Delete(LocalFile); ftpcon.DownloadFile(LocalFile, RemoteFile); Console.WriteLine(Strings.Get("JavaInstall")); ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = LocalFile; psi.WorkingDirectory = Path.GetDirectoryName(LocalFile); psi.Verb = "runas"; psi.Arguments = "/s"; psi.UseShellExecute = true; var process = Process.Start(psi); process.WaitForExit(); File.Delete(LocalFile); } catch (Exception ex) { Console.WriteLine(Strings.Get("JavaError") + ex.Message); Console.WriteLine(Strings.Get("PressKey")); Console.ReadKey(); } }
public void DownloadAttachment(Attachment attachment, string localPath) { Procedure procedure = (from p in appManager.ApplicationDb.Procedures from a in p.Attachments where a.Id == attachment.Id select p).FirstOrDefault(); MedicalRecord medicalRecord = (from m in appManager.ApplicationDb.MedicalRecords from p in m.Procedures where p.Id == procedure.Id select m).FirstOrDefault(); Patient patient = (from p in appManager.ApplicationDb.Patients from m in p.MedicalHistory where m.Id == medicalRecord.Id select p).FirstOrDefault(); string medicalRecordPath = String.Format("{0}/{1}", patient.Ssn, medicalRecord.Id); string ftpFileName = String.Format("{0}/{1}_{2}_{3}", medicalRecordPath, procedure.Id, attachment.Id, attachment.File); FTPConnection ftp = new FTPConnection("193.224.69.39", "balu", "szoftech", "hubasky/attachments"); ftp.DownloadFile(ftpFileName, localPath); }
/// <summary>Transfer back and forth multiple times</summary> internal override void BulkTransfer(string localFile) { // put to a random filename muliple times string filename = GenerateRandomFilename(); log.Debug("Bulk transfer count=" + bulkCount); for (int i = 0; i < bulkCount; i++) { ftp.UploadFile(localDataDir + localFile, filename); // get it back ftp.DownloadFile(localDataDir + filename, filename); } // delete remote file ftp.DeleteFile(filename); // check equality of local files AssertIdentical(localDataDir + localFile, localDataDir + filename); // and delete local file FileInfo local = new FileInfo(localDataDir + filename); local.Delete(); }
/// <summary> /// 下载一个文件 /// </summary> /// <param name="localFileName"></param> /// <param name="remoteFileName"></param> /// <param name="connection"></param> private void DownloadFile(string localFileName, string remoteFileName, FTPConnection connection) { connection.DownloadFile(localFileName, remoteFileName); }
public void DownloadFile(string localPath, string remoteFile) { ftp.DownloadFile(localPath, remoteFile); }
public void Download(FTPFile file, string destination) { connection.DownloadFile(destination, file.Name); }