/// <summary> /// 从指定的ftp服务器下载指定的文件到本地 /// </summary> /// <param name="name">FTP名称</param> /// <param name="name">远程文件</param> /// <param name="name">本地文件</param> protected virtual bool DownloadFile(string name, string remoteFile, string localFile) { if (GlobalMethods.Misc.IsEmptyString(name)) { return(false); } if (this.m_ftpAccessDict == null || this.m_ftpAccessDict.Count <= 0) { return(false); } if (!this.m_ftpAccessDict.ContainsKey(name)) { return(false); } bool success = false; FtpAccess ftpAccess = this.m_ftpAccessDict[name]; if (ftpAccess.OpenConnection()) { string localDirectory = GlobalMethods.IO.GetFilePath(localFile); if (GlobalMethods.IO.CreateDirectory(localDirectory)) { success = ftpAccess.Download(remoteFile, localFile); } } ftpAccess.CloseConnection(); return(false); }
/// <summary> /// 获取XDBFtp访问类 /// </summary> /// <returns>FtpAccess对象</returns> public FtpAccess GetXDBFtpAccess() { if (this.m_XDBFtpAccess != null) { return(this.m_XDBFtpAccess); } if (this.m_ConfigAccess == null) { this.m_ConfigAccess = new ConfigAccess(); } FtpConfig ftpConfig = null; short shRet = this.m_ConfigAccess.GetXDBFtpParams(ref ftpConfig); if (shRet != SystemData.ReturnValue.OK) { return(null); } if (ftpConfig == null) { return(null); } this.m_XDBFtpAccess = new FtpAccess(); this.m_XDBFtpAccess.FtpIP = ftpConfig.FtpIP; this.m_XDBFtpAccess.FtpPort = ftpConfig.FtpPort; this.m_XDBFtpAccess.UserName = ftpConfig.FtpUser; this.m_XDBFtpAccess.Password = ftpConfig.FtpPwd; this.m_XDBFtpAccess.FtpMode = ftpConfig.FtpMode; return(this.m_XDBFtpAccess); }
public void TestMethod3() { //日期判断 FtpAccess ftpAccess = new FtpAccess(); ftpAccess.FtpIP = "192.168.1.63"; ftpAccess.FtpPort = 9000; ftpAccess.Password = "******"; ftpAccess.UserName = "******"; ftpAccess.FtpMode = FtpMode.PASV; ftpAccess.OpenConnection(); string szLocalFile = @"D:\svn\MDP\MedDoc\2-SourceCode\Trunk\Debug\Documents\Temp\68360_34130_20160513153221_5116.xml"; string szRemoteFile = "/MEDDOC/68360_34130_20160513153221_5116.xml"; bool result = ftpAccess.Upload(szLocalFile, szRemoteFile); ftpAccess.CloseConnection(); }
// Define the AuthorizeUser method. FtpAccess IFtpAuthorizationProvider.GetUserAccessPermission( string pszSessionId, string pszSiteName, string pszVirtualPath, string pszUserName) { // Define the default access. FtpAccess _ftpAccess = FtpAccess.None; // Validate that the user and virtual path are not empty. if (String.IsNullOrEmpty(pszUserName) || String.IsNullOrEmpty(pszVirtualPath)) { // Return false (authorization failed) if either are empty. return(FtpAccess.None); } else { try { // Retrieve the user/role data from the XML file. ReadXmlDataStore(); // Create a user object. XmlUserData user; // Test if the user name is in the dictionary of users. if (_XmlUserData.TryGetValue(pszUserName, out user)) { // Loop through the user's roles. foreach (KeyValuePair <string, FtpAccess> rule in user.Rules) { // Test if the virtual path matches an authorization rule. // Note: This is a very simple path search. if (pszVirtualPath.StartsWith(rule.Key)) { _ftpAccess = rule.Value; } } } } catch (Exception ex) { // Raise an exception if an error occurs. throw new ProviderException(ex.Message); } } return(_ftpAccess); }
/// <summary> /// 创建一个新的FTP服务 /// </summary> /// <param name="name">FTP服务名称</param> /// <param name="ip">IP地址</param> /// <param name="port">端口号</param> /// <param name="user">用户名</param> /// <param name="pwd">密码</param> protected void CreateFtpService(string name, string ip, int port, string user, string pwd) { if (GlobalMethods.Misc.IsEmptyString(name)) { return; } if (this.m_ftpAccessDict == null) { this.m_ftpAccessDict = new Dictionary <string, FtpAccess>(); } if (!this.m_ftpAccessDict.ContainsKey(name)) { FtpAccess ftpAccess = new FtpAccess(); ftpAccess.FtpIP = ip; ftpAccess.FtpPort = port; ftpAccess.UserName = user; ftpAccess.Password = pwd; this.m_ftpAccessDict.Add(name, ftpAccess); } }
/// <summary> /// Constructor de Entrada. Instancia una sesion de facturacion electronica /// </summary> /// <param name="Config">Path de ubicacion del archivo de configuracion</param> /// <param name="User">Usuario de sistema</param> //Constructor de Entrada public FacturacionElectronica(string Config, string User) { //Verificacion de existencia de archivo de configuracion if (!File.Exists(Config)) { throw new Exception("Archivo de configuracion no existe"); } //Seteo de varuales de control this.ConfigFile = Config; this.UserSystem = User; //Intanciamiento de clases globales this.utl = new Utils(); string errorPath = utl.convertirString(utl.getConfigValue(this.ConfigFile, "SERVICES", "errors")); this.con = new ConMySQL(this.ConfigFile, this.UserSystem); this.err = new Errors(this.UserSystem, "ElecDocs", errorPath); this.ftp = new FtpAccess(this.ConfigFile, this.UserSystem); }
/// <summary> /// 获取FTP图片 /// </summary> /// <param name="recPaperInfo"></param> /// <param name="fileName"></param> /// <returns></returns> public short GetImageFromFtp(RecPaper recPaperInfo, string fileName, ref string szLocalFile) { if (recPaperInfo == null) { return(SystemData.ReturnValue.FAILED); } FtpAccess recPaperFtpAccess = base.GetRecPaperFtpAccess(); try { if (recPaperInfo == null) { return(SystemData.ReturnValue.PARAM_ERROR); } if (!recPaperFtpAccess.OpenConnection()) { return(SystemData.ReturnValue.FAILED); } string szRemoteFilePath = GetRecPaperRemoteDir(recPaperInfo) + fileName; szLocalFile = this.GetImageLocalFile(fileName); if (!recPaperFtpAccess.ResExists(szRemoteFilePath, false)) { return(SystemData.ReturnValue.FAILED); } if (!recPaperFtpAccess.Download(szRemoteFilePath, szLocalFile)) { szLocalFile = ""; return(SystemData.ReturnValue.FAILED); } } finally { if (recPaperFtpAccess != null) { recPaperFtpAccess.CloseConnection(); } } return(SystemData.ReturnValue.OK); }
private void InitializeConfig() { this.m_upgradeVersion = null; this.m_upgradeFtpAccess = null; List <ConfigInfo> configInfos = null; ConfigAccess.Instance.GetConfigData("UPGRADE", null, ref configInfos); if (configInfos == null || configInfos.Count <= 0) { return; } this.m_upgradeFtpAccess = new FtpAccess(); foreach (ConfigInfo configInfo in configInfos) { if (configInfo.ConfigName == "IP") { this.m_upgradeFtpAccess.FtpIP = configInfo.ConfigValue; } else if (configInfo.ConfigName == "PORT") { this.m_upgradeFtpAccess.FtpPort = GlobalMethods.Convert.StringToValue(configInfo.ConfigValue, 21); } else if (configInfo.ConfigName == "USER") { this.m_upgradeFtpAccess.UserName = configInfo.ConfigValue; } else if (configInfo.ConfigName == "PWD") { this.m_upgradeFtpAccess.Password = configInfo.ConfigValue; } else if (configInfo.ConfigName == "MEDQC_VERSION") { this.m_upgradeVersion = configInfo.ConfigValue; } } }
// Retrieve the user/role data from the XML file. private void ReadXmlDataStore() { // Lock the provider while the data is retrieved. lock (this) { try { // Test if the dictionary already has data. if (_XmlUserData.Count == 0) { // Create an XML document object and load the data XML file XPathDocument xmlDocument = new XPathDocument(_xmlFileName); // Create a navigator object to navigate through the XML file. XPathNavigator xmlNavigator = xmlDocument.CreateNavigator(); // Loop through the users in the XML file. foreach (XPathNavigator node in xmlNavigator.Select("/Users/User")) { // Retrieve a user name. string userName = GetInnerText(node, "UserName"); // Retrieve the user's password. string password = GetInnerText(node, "Password"); // Test if the data is empty. if ((String.IsNullOrEmpty(userName) == false) && (String.IsNullOrEmpty(password) == false)) { // Retrieve the user's roles. string xmlRoles = GetInnerText(node, "Roles"); // Create a string array for the user roles. string[] userRoles = new string[0]; // Test if the user has any roles defined. if (String.IsNullOrEmpty(xmlRoles) == false) { // Split the roles by comma. userRoles = xmlRoles.Split(','); } // Create a dictionary to hold the user's authorization rules. Dictionary <string, FtpAccess> userRules = new Dictionary <string, FtpAccess>( StringComparer.InvariantCultureIgnoreCase); // Loop through the set of authorization rules for the user. foreach (XPathNavigator rule in node.Select("Rules/Rule")) { // Retrieve the URL path for the authorization rule. string xmlPath = rule.GetAttribute("path", string.Empty); // Strip trailing slashes from paths. if (xmlPath.EndsWith("/") && xmlPath.Length > 1) { xmlPath = xmlPath.Substring(0, xmlPath.Length - 1); } // Retrieve the user's permissionsfor the authorization rule. string xmlPermissions = rule.GetAttribute("permissions", string.Empty); // Parse the FTP access permissions for the authorization rule. FtpAccess userPermissions = FtpAccess.None; switch (xmlPermissions.Replace(" ", "").ToLower()) { case "read": userPermissions = FtpAccess.Read; break; case "write": userPermissions = FtpAccess.Write; break; case "read,write": case "write,read": userPermissions = FtpAccess.ReadWrite; break; default: userPermissions = FtpAccess.None; break; } // Add the authorization rule to the dictionary. userRules.Add(xmlPath, userPermissions); } // Create a user data class. XmlUserData userData = new XmlUserData(password, userRoles, userRules); // Store the user data in the dictionary. _XmlUserData.Add(userName, userData); } } } } catch (Exception ex) { // Raise an exception if an error occurs. throw new ProviderException(ex.Message); } } }