private FTP_Class ftp; ///////// #region 构造函数 /// <summary> /// 构造函数,初始化工程名,ip,用户id,密码 /// </summary> /// <param name="ProName">工程名</param> /// <param name="ftpIP">ip</param> /// <param name="ftpUser">用户id</param> /// <param name="PassWord">密码</param> public clsProject(string ProName, string ftpIP, string ftpUser, string PassWord) { this._ProName = ProName; this._ftpIP = ftpIP; this._ftpUSER = ftpUser; this._ftpPassWord = PassWord; ftp = new FTP_Class(_ftpIP, _ftpUSER, _ftpPassWord); ftp.FtpUpDown(_ftpIP, _ftpUSER, _ftpPassWord); }
/// <summary> /// 建立工程,成功返回true,失败返回false /// </summary> /// <returns></returns> public bool Create() { if (null == _ProName || "" == _ProName) { return(false); } try { XmlDocument Doc = new XmlDocument(); Doc.Load(ModData.v_ProjectInfoXML); XmlNodeList Nodelist = Doc.SelectSingleNode("项目目录").ChildNodes; if (null == Nodelist) { return(false); } StringBuilder result = new StringBuilder(); String[] Floders; foreach (XmlNode Node1 in Nodelist) { result.Append(Node1.InnerText); result.Append("\n"); } result.Remove(result.ToString().LastIndexOf('\n'), 1); Floders = result.ToString().Split('\n'); string err; ftp.MakeDir(_ProName, out err); if (null == Floders) { return(false); } foreach (string FloderName in Floders) { string errs = ""; ftp.MakeDir(_ProName + "/" + FloderName.Trim(), out errs); if ("Succeed" != err) { return(false); } } return(true); } catch { return(false); } finally { if (null != ftp) { ftp = null; } } }
public override void OnClick() { if (m_Hook.DataInfoGrid.Rows.Count <= 0) { return; } FolderBrowserDialog GetFileInfo = new FolderBrowserDialog(); if (GetFileInfo.ShowDialog() == DialogResult.OK) { //System.IO.FileInfo fileinfo = new System.IO.FileInfo(GetFileInfo.FileName); string FileSavePath = GetFileInfo.SelectedPath; FileSavePath = FileSavePath.Replace("\\", "/");//文件保存路径 //string FileSaveName = fileinfo.Name; //文件保存名 string serverStr = ""; //服务器 string user = ""; //用户 string password = ""; //密码 #region 通过树节点获取IP地址 DevComponents.AdvTree.Node DBNode = null; string treeNodeType = m_Hook.ProjectTree.SelectedNode.DataKey.ToString(); if (treeNodeType == "") { return; } DBNode = m_Hook.ProjectTree.SelectedNode;//数据库节点,根节点 while (DBNode.Parent != null) { DBNode = DBNode.Parent; } if (DBNode == null) { return; } if (DBNode.DataKey.ToString() != EnumTreeNodeType.DATABASE.ToString()) { return; } if (DBNode.Name != "文件连接") { return; } XmlElement connElem = DBNode.Tag as XmlElement; if (connElem == null) { return; } serverStr = connElem.GetAttribute("服务器"); user = connElem.GetAttribute("用户"); password = connElem.GetAttribute("密码"); if (serverStr == "" || user == "" || password == "") { return; } //string conStr = connElem.GetAttribute("MetaDBConn");//元数据库连接信息 #endregion for (int i = 0; i < m_Hook.DataInfoGrid.RowCount; i++) { if (false == m_Hook.DataInfoGrid.Rows[i].Selected) { continue; } string fileName = ""; //文件名 string filePath = ""; //文件FTP路径 fileName = m_Hook.DataInfoGrid.Rows[i].Cells["数据文件名"].FormattedValue.ToString().Trim(); filePath = m_Hook.DataInfoGrid.Rows[i].Cells["存储位置"].FormattedValue.ToString().Trim(); if (fileName == "" || filePath == "") { return; } string error = ""; //执行下载数据 FTP_Class clsFtp = new FTP_Class(serverStr, user, password); string[] fNameArr = clsFtp.GetFileList(filePath, out error); if (error != "Succeed") { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取文件列表失败!"); return; } if (fNameArr == null) { //控制点数据导出,特殊处理 continue; } else { #region 其他数据下载 for (int j = 0; j < fNameArr.Length; j++) { string ttName = fNameArr[j]; if (ttName.Contains(fileName.Substring(0, fileName.LastIndexOf('.')))) { if (File.Exists(FileSavePath + "/" + ttName)) { if (SysCommon.Error.ErrorHandle.ShowFrmInformation("确定", "取消", "存在同名文件,是否替换?")) { File.Delete(FileSavePath + "/" + ttName); } else { return; } } bool state = ModDBOperator.DownloadFile(serverStr, user, password, filePath, ttName, ttName, FileSavePath, out error); if (!state) { SysCommon.Error.frmInformation eerorFrm = new SysCommon.Error.frmInformation("是", "否", "数据文件\n'" + filePath + "\\" + ttName + "'\n下载失败。原因为:\n" + error + "!\n是否继续下载?"); eerorFrm.Owner = (m_Hook as Plugin.Application.IAppFormRef).MainForm; if (eerorFrm.ShowDialog() == DialogResult.OK) { continue; } else { return; } } } } #endregion } } SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "下载完成!"); } }
public override void OnClick() { FolderBrowserDialog GetFileInfo = new FolderBrowserDialog(); if (GetFileInfo.ShowDialog() == DialogResult.OK) { //System.IO.FileInfo fileinfo = new System.IO.FileInfo(GetFileInfo.FileName); //string FileSavePath = fileinfo.DirectoryName; string FileSavePath = GetFileInfo.SelectedPath; FileSavePath = FileSavePath.Replace("\\", "/"); //文件保存路径 string serverStr = ""; //服务器 string user = ""; //用户 string password = ""; //密码 string fileName = ""; //文件名 string filePath = ""; //文件FTP路径 DevComponents.AdvTree.Node DBNode = null; //数据库节点 string treeNodeType = m_Hook.ProjectTree.SelectedNode.DataKey.ToString(); if (m_Hook.ProjectTree.SelectedNode.Name == "") { return; } filePath = m_Hook.ProjectTree.SelectedNode.Name; //数据文件存储路径 if (m_Hook.ProjectTree.SelectedNode.Text == "") { return; } fileName = m_Hook.ProjectTree.SelectedNode.Text; //数据文件名 if (m_Hook.ProjectTree.SelectedNode.Tag == null) { return; } //if (File.Exists(FileSavePath + "/" + fileName)) //{ // if (SysCommon.Error.ErrorHandle.ShowFrmInformation("确定", "取消", "存在同名文件,是否替换?")) // { // File.Delete(FileSavePath + "/" + fileName); // } // else // return; //} //获得FTP地址 DBNode = m_Hook.ProjectTree.SelectedNode;//数据库节点,根节点 while (DBNode.Parent != null) { DBNode = DBNode.Parent; } if (DBNode == null) { return; } if (DBNode.DataKey.ToString() != EnumTreeNodeType.DATABASE.ToString()) { return; } if (DBNode.Name != "文件连接") { return; } XmlElement connElem = DBNode.Tag as XmlElement; if (connElem == null) { return; } serverStr = connElem.GetAttribute("服务器"); user = connElem.GetAttribute("用户"); password = connElem.GetAttribute("密码"); if (serverStr == "" || user == "" || password == "") { return; } string error = ""; FTP_Class clsFtp = new FTP_Class(serverStr, user, password); string[] fNameArr = clsFtp.GetFileList(filePath, out error); if (error != "Succeed") { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取文件列表失败!"); return; } for (int j = 0; j < fNameArr.Length; j++) { string ttName = fNameArr[j]; if (ttName.Contains(fileName.Substring(0, fileName.LastIndexOf('.')))) { if (File.Exists(FileSavePath + "/" + ttName)) { if (SysCommon.Error.ErrorHandle.ShowFrmInformation("确定", "取消", "存在同名文件,是否替换?")) { File.Delete(FileSavePath + "/" + ttName); } else { return; } } bool state = ModDBOperator.DownloadFile(serverStr, user, password, filePath, ttName, ttName, FileSavePath, out error); if (!state) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("错误", "下载数据失败,数据文件为:\n'" + filePath + "\\" + ttName + "'"); return; } } } SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "下载完成!"); } }