예제 #1
0
 public void SetupFtp()
 {
     string path = Path.Combine(PropertyService.ConfigDirectory, "ftp.config");
     if (File.Exists(path) || File.Exists(Path.Combine(PropertyService.ConfigDirectory, "ftp.cconfig")))
     {
         FtpSetting setting = FtpSetting.Get(path);
         if (string.IsNullOrEmpty(setting.Host))
         {
             throw new ArgumentNullException("host");
         }
         this.ftpClient = new FTPclient();
         this.ftpClient.Hostname = setting.Host + "/办事指引";
         if (!string.IsNullOrEmpty(setting.User))
         {
             this.ftpClient.Username = setting.User;
             this.ftpClient.Password = setting.Password;
         }
     }
 }
예제 #2
0
 private void UploadComponent(string rootpath, string path, string name)
 {
     FTPclient pclient = new FTPclient {
         Hostname = this.txtHost.Text + "/" + this.txtFtpLocation.Text
     };
     if (!string.IsNullOrEmpty(this.txtUser.Text))
     {
         pclient.Username = this.txtUser.Text;
         pclient.Password = this.txtPwd.Text;
     }
     string str = path.Replace(rootpath, "");
     string filename = str + "/component.xml";
     string localFilename = Path.Combine(path, name + string.Format("component{0}.xml", DateTime.Now.ToString("yyMMdd_hhmmss")));
     Dictionary<string, string[]> oldfilevers = new Dictionary<string, string[]>();
     if (pclient.FtpFileExists(filename) && pclient.Download(filename, localFilename, true))
     {
         oldfilevers = this.GetOldFileVersions(localFilename);
     }
     Dictionary<string, string[]> filevers = new Dictionary<string, string[]>();
     this.GetFileVersions(path, path, oldfilevers, ref filevers);
     bool flag = false;
     foreach (KeyValuePair<string, string[]> pair in filevers)
     {
         string sourceFilename = str + pair.Key;
         bool flag2 = pclient.FtpFileExists(str + pair.Key);
         string str5 = ((oldfilevers == null) || !oldfilevers.ContainsKey(pair.Key)) ? "1.50.00" : ((string) oldfilevers[pair.Key][0]);
         if (((oldfilevers == null) && ((pair.Value[0].CompareTo("1.50.00") > 0) || !flag2)) || ((oldfilevers != null) && (!oldfilevers.ContainsKey(pair.Key) || (pair.Value[0].CompareTo((string) oldfilevers[pair.Key][0]) > 0))))
         {
             if (flag2)
             {
                 string str6 = sourceFilename + str5;
                 if (pclient.FtpFileExists(str6))
                 {
                     pclient.FtpDelete(str6);
                     this.WriteLog(string.Format("成功删除了已存在的同名备份文件:{0}", str6));
                 }
                 pclient.FtpRename(sourceFilename, str6);
             }
             else
             {
                 this.WriteLog(string.Format("ftp服务器上没有找到:{0}{1} 文件,请确认", path, pair.Key));
             }
             if (pclient.Upload(path + pair.Key, str + pair.Key))
             {
                 flag = true;
                 this.WriteLog(string.Format("上传:{0}{1} 成功", path, pair.Key));
             }
             else
             {
                 this.WriteErrLog(string.Format("上传{0}{1}不成功,你需要排除错误后重新全部上传", path, pair.Key));
                 return;
             }
         }
     }
     if (flag)
     {
         string str7 = Path.Combine(path, name + "component.xml");
         FileStream stream = new FileStream(str7, FileMode.Create);
         StreamWriter writer = new StreamWriter(stream, Encoding.UTF8);
         writer.Write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n");
         writer.Write(string.Format("<Component Name=\"{0}\">\r\n", name));
         writer.Write("\t<Files>\r\n");
         foreach (KeyValuePair<string, string[]> pair2 in filevers)
         {
             writer.Write(string.Format("\t\t<File Name=\"{0}\" Ver=\"{1}\" Checksum=\"{2}\" />\r\n", pair2.Key, pair2.Value[0], pair2.Value[1]));
         }
         writer.Write("\t</Files>\r\n");
         writer.Write("</Component>\r\n");
         writer.Close();
         stream.Close();
         this.WriteLog(string.Format("生成{0}成功", Path.Combine(path, name + "component.xml")));
         if (pclient.FtpFileExists(filename))
         {
             pclient.FtpRename(filename, filename + DateTime.Now.ToString("yyMdHHmmss"));
         }
         if (pclient.Upload(str7, filename))
         {
             this.WriteLog(string.Format("上传:{0}  成功", str7));
         }
     }
     if (this.checkBox1.Checked || flag)
     {
         string changelog = Path.Combine(path, name + "changelog.xml");
         if (this.GetLogs(path, changelog))
         {
             string str9 = string.Format("{0}/{1}changelog.xml", str, name);
             if (pclient.FtpFileExists(str9))
             {
                 pclient.FtpRename(str9, str9 + DateTime.Now.ToString("yyMdHHmmss"));
             }
             if (pclient.Upload(changelog, str9))
             {
                 this.WriteLog(string.Format("上传:{0}  成功", changelog));
             }
         }
     }
 }
예제 #3
0
 public void SetupFtp()
 {
     SkyMap.Net.WebCamLibrary.FtpSetting setting = SkyMap.Net.WebCamLibrary.FtpSetting.Get(Path.Combine(PropertyService.ConfigDirectory, "ftpCamera.config"));
     if (string.IsNullOrEmpty(setting.Host))
     {
         throw new ArgumentNullException("host");
     }
     this.ftpClient = new FTPclient();
     this.ftpClient.Hostname = setting.Host + "/" + setting.Path;
     if (!string.IsNullOrEmpty(setting.User))
     {
         this.ftpClient.Username = setting.User;
         this.ftpClient.Password = setting.Password;
     }
 }
예제 #4
0
 public void Initialize(string host, string user, string pwd, string ftpPath, string subftppath, string localPath)
 {
     if (string.IsNullOrEmpty(host))
     {
         throw new ArgumentNullException("host");
     }
     this.ftpClient = new FTPclient();
     this.ftpClient.Hostname = host + "/" + ftpPath;
     if (!string.IsNullOrEmpty(user))
     {
         this.ftpClient.Username = user;
         this.ftpClient.Password = pwd;
     }
     this.ftpdir = subftppath;
     this.localPath = localPath;
 }