public void DownloadDir( ) { try { clsFTP ftp = new clsFTP(mLog); ftp.setFace(this); clsConfig config = new clsConfig(); string[] monitorDirectory = config.GetConfigValue(clsConfig.ConfigItem.MonitorRootFolder).Split(new char[] { '\\', '\\' }); int FtpPort = 21; try { string portStr = config.GetConfigValue(clsConfig.ConfigItem.FTPServerPort); FtpPort = int.Parse(portStr); } catch { FtpPort = 21; } mLog.WriteSingleLog("Start to connect to FTP."); ftp.Connect(config.GetConfigValue(clsConfig.ConfigItem.FTPServerIP), FtpPort, config.GetConfigValue(clsConfig.ConfigItem.FTPAccount), config.GetConfigValue(clsConfig.ConfigItem.FTPPassword), string.Empty, "DEFAULT"); mLog.WriteSingleLog("Connect to FTP success."); //if exists,add additional sequence to identify for (int i = 0; i < monitorDirectory.Length; i++) { if (ftp.Exists(monitorDirectory[i])) { string localFile =updateFolder ; ftp.FTPDownloadDir(localFile, monitorDirectory[i]); mLog.WriteSingleLog("FTP get OK ==> " + "local file: " + localFile + " | remote file: " + monitorDirectory[i]); } else { mLog.WriteSingleLog("FTP get faild ==> | remote file: " + monitorDirectory[i]); MessageBox.Show( "服务器上没有" + monitorDirectory[i] ,"提示" ); return; } } ftp.Disconnect(); setPersent(100); setInfo("下载完成!"); Install(); return; } catch (Exception ex) { throw ex; } }
public void getConfigFile( ) { //string updateFolder = Application.StartupPath + "\\_Update\\"; //DirectoryInfo info1 = new DirectoryInfo(updateFolder); //if (!info1.Exists) //{ // info1.Create(); //} try { clsFTP ftp = new clsFTP(mLog); clsConfig config = new clsConfig(); string[] monitorDirectory = config.GetConfigValue(clsConfig.ConfigItem.MonitorRootFolder).Split(new char[] { '\\', '\\' }); int FtpPort = 21; try { string portStr = config.GetConfigValue(clsConfig.ConfigItem.FTPServerPort); FtpPort = int.Parse(portStr); } catch { FtpPort = 21; } mLog.WriteSingleLog( "Start to connect to FTP."); ftp.Connect(config.GetConfigValue(clsConfig.ConfigItem.FTPServerIP), FtpPort, config.GetConfigValue(clsConfig.ConfigItem.FTPAccount), config.GetConfigValue(clsConfig.ConfigItem.FTPPassword), string.Empty, "DEFAULT"); mLog.WriteSingleLog( "Connect to FTP success."); string remoteFileName =monitorDirectory[0] + "\\UpdateFile.xml"; string localFile = "UpdateFile_tmp.xml"; //if exists,add additional sequence to identify if (ftp.Exists(remoteFileName)) { ftp.FTPDownloadFile(localFile, remoteFileName); mLog.WriteSingleLog("FTP get config file OK ==> " + "local file: " + localFile + " | remote file: " + remoteFileName); } else { mLog.WriteSingleLog("FTP get t config file faild ==> " + "local file: " + localFile + " | remote file: " + remoteFileName); } ftp.Disconnect(); } catch (Exception ex) { throw ex; } }