public virtual void SetUp() { host = TestContextParameter("gx_ftp_host"); user = TestContextParameter("gx_ftps_user"); password = TestContextParameter("gx_ftps_password"); localPath = Path.Combine(BASE_PATH, "Temp", "ftps", "ftpstest.txt"); remoteDir = "/files"; remoteFilePath = "/files/ftpstest.txt"; localDir = Path.Combine(BASE_PATH, "Temp", "ftps", "back"); port = 21; connectionMode = "PASSIVE"; forceEncryption = true; encoding = "BINARY"; encryptionMode = "EXPLICIT"; protocol = "TLS1_2"; string certificateConentBase64 = TestContextParameter("gx_ftp_certificate_content_base64"); trustStorePath = Path.Combine(BASE_PATH, "Temp", "ftps", "ftps_cert.pfx"); File.WriteAllBytes(trustStorePath, System.Convert.FromBase64String(certificateConentBase64)); trustStorePassword = TestContextParameter("gx_ftps_trust_store_password"); whiteList = new ExtensionsWhiteList(); whiteList.SetExtension(".txt"); whiteList.SetExtension(".pdf"); imagePath = Path.Combine(BASE_PATH, "Temp", "icon.png"); }
public override bool Connect(SftpOptions options) { if (options.HasError()) { this.error = options.GetError(); return(false); } bool useKey = false; if (SecurityUtils.compareStrings("", options.KeyPath) || SecurityUtils.compareStrings("", options.User) || SecurityUtils.compareStrings("", options.KeyPassword)) { useKey = false; if (SecurityUtils.compareStrings("", options.User) || SecurityUtils.compareStrings("", options.Password)) { this.error.setError("SF001", "Authentication misconfiguration"); return(false); } else { useKey = false; } } else { useKey = true; } if (SecurityUtils.compareStrings("", options.Host)) { this.error.setError("SF003", "Empty host"); return(false); } try { SetupChannelSftp(options, useKey); if (this.channel == null) { return(false); } if (!this.channel.IsConnected) { this.channel.Connect(); } } catch (Exception e) { this.error.setError("SF004", e.Message); return(false); } this.whiteList = options.WhiteList; return(true); }
public SftpOptions() : base() { this.host = ""; this.port = 22; this.user = ""; this.password = ""; this.keyPath = ""; this.keyPassword = ""; this.allowHostKeyChecking = true; this.knownHostsPath = ""; this._whiteList = null; }
public FtpsOptions() : base() { this._host = ""; this._port = 21; this._user = ""; this._password = ""; this._forceEncryption = true; this._connectionMode = FtpConnectionMode.PASSIVE; this._encoding = FtpEncoding.BINARY; this._encryptionMode = FtpEncryptionMode.EXPLICIT; this._trustStorePath = ""; this._trustStorePassword = ""; this._protocol = FtpsProtocol.TLS1_2; this._whiteList = null; }
public SftpClient() : base() { this.channel = null; this.fingerprint = false; this.whiteList = null; }
public override bool Connect(FtpsOptions options) { if (options.HasError()) { this.error = options.GetError(); return(false); } if (SecurityUtils.compareStrings("", options.Host) || SecurityUtils.compareStrings("", options.User) || SecurityUtils.compareStrings("", options.Password)) { this.error.setError("FS001", "Empty connection data"); return(false); } this.client = new FtpClient { Host = options.Host, Port = options.Port, Credentials = new NetworkCredential(options.User, options.Password), DataConnectionType = SetConnectionMode(options), EncryptionMode = SetEncryptionMode(options), Encoding = Encoding.UTF8, }; this.client.DownloadDataType = SetEncoding(options); SslProtocols protocols = SetProtocol(options);; if (protocols == SslProtocols.None) { return(false); } this.client.SslProtocols = protocols; this.client.DataConnectionEncryption = options.ForceEncryption; if (SecurityUtils.compareStrings("", options.TrustStorePath)) { this.client.ValidateCertificate += (control, e1) => { e1.Accept = true; }; } else { X509Certificate2 cert_grt = new X509Certificate2(options.TrustStorePath, options.TrustStorePassword); client.ValidateCertificate += (control, e1) => { X509Chain verify = new X509Chain(); verify.Build(new X509Certificate2(e1.Certificate)); e1.Accept = SecurityUtils.compareStrings(verify.ChainElements[verify.ChainElements.Count - 1].Certificate.Thumbprint, cert_grt.Thumbprint); }; } try { this.client.Connect(); if (!this.client.LastReply.Success) { this.client.Disconnect(); this.error.setError("FS008", "Connection error"); return(false); } } catch (Exception e) { this.error.setError("FS002", "Connection error " + e.Message); this.client = null; return(false); } if (!this.client.IsConnected) { this.error.setError("FS009", "Connection error"); return(false); } this.whiteList = options.WhiteList; return(true); }
public FtpsClient() : base() { this.client = null; this.whiteList = null; }