コード例 #1
0
        internal SessionOptions GetSessionOptions()
        {
            SessionOptions sessionOptions = new SessionOptions
            {
                Protocol   = (Protocol)Enum.Parse(typeof(Protocol), Protocol.ToString(), true),
                HostName   = HostName,
                UserName   = UserName,
                Password   = SecurityService.DecyptValue(Password),
                PortNumber = PortNumber
            };

            if (Protocol == WinSCPProtocol.Ftp)
            {
                sessionOptions.FtpSecure = (FtpSecure)Enum.Parse(typeof(FtpSecure), FtpSecure.ToString(), true);
                sessionOptions.GiveUpSecurityAndAcceptAnyTlsHostCertificate = AcceptAnyTlsHostCertificate;
            }
            else if (Protocol == WinSCPProtocol.SFtp)
            {
                sessionOptions.GiveUpSecurityAndAcceptAnySshHostKey = AcceptAnySshHostKey;
                sessionOptions.SshHostKeyFingerprint = string.IsNullOrEmpty(SshHostKeyFingerprint) ? null : SshHostKeyFingerprint;
                sessionOptions.PrivateKeyPassphrase  = string.IsNullOrEmpty(SshPrivateKeyPassphrase) ? null : SecurityService.DecyptValue(SshPrivateKeyPassphrase);
                sessionOptions.SshPrivateKeyPath     = string.IsNullOrEmpty(SshPrivateKeyPath) ? null : SshPrivateKeyPath;
            }

            return(sessionOptions);
        }
コード例 #2
0
        /// <summary>
        /// FTP / FTPs connection
        /// </summary>
        /// <param name="hostname"></param>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="ftpSecure"></param>
        /// <param name="portNumber"></param>
        /// <param name="tlsHostCertificateFingerprint"></param>
        public SFtpClient(string hostname, string username, string password, FtpSecure ftpSecure, string tlsHostCertificateFingerprint = "", int portNumber = 21)
        {
            _sessionOptions = new SessionOptions
            {
                Protocol   = Protocol.Ftp,
                HostName   = hostname,
                UserName   = username,
                Password   = password,
                PortNumber = portNumber,
            };

            if (ftpSecure == FtpSecure.None)
            {
                // Do nothing regarding secure set up
            }
            else
            {
                _sessionOptions.FtpSecure = ftpSecure;
                if (string.IsNullOrWhiteSpace(tlsHostCertificateFingerprint))
                {
                    // Can turn off finger print verification
                    _sessionOptions.GiveUpSecurityAndAcceptAnyTlsHostCertificate = true;
                }
                else
                {
                    // This property is for FTPS
                    _sessionOptions.TlsHostCertificateFingerprint = tlsHostCertificateFingerprint;
                }
            }
        }
コード例 #3
0
        public bool reconnectFTPS(FtpSecure FTPSmode)
        {
            session.Dispose();

            ftpOptions = new SessionOptions
            {
                Protocol  = ftpProtocol,
                HostName  = creds.address,
                UserName  = creds.username,
                Password  = creds.password,
                FtpSecure = FTPSmode,
                SslHostCertificateFingerprint = creds.FTPSfingerP
            };

            return(startSession());
        }
コード例 #4
0
 public override List <ProviderParameter> GetInitializationParameters()
 {
     return(new List <ProviderParameter>
     {
         new ProviderParameter("Path", Path, GetConfigKey("Path")),
         new ProviderParameter("FilterPattern", FilterPattern, GetConfigKey("FilterPattern")),
         new ProviderParameter("ModifiedSinceUTC", ModifiedSinceUTC, GetConfigKey("ModifiedSinceUTC")),
         new ProviderParameter("RecuirseFolders", RecuirseFolders.ToString(), GetConfigKey("RecuirseFolders")),
         new ProviderParameter("WebFriendlyPaths", WebFriendlyPaths.ToString(), GetConfigKey("WebFriendlyPaths")),
         new ProviderParameter("Protocol", Protocol.ToString(), GetConfigKey("Protocol")),
         new ProviderParameter("HostName", HostName, GetConfigKey("HostName")),
         new ProviderParameter("PortNumber", PortNumber.ToString(CultureInfo.InvariantCulture), GetConfigKey("HostName")),
         new ProviderParameter("UserName", UserName, GetConfigKey("UserName")),
         new ProviderParameter("Password", SecurityService.EncryptValue(Password), GetConfigKey("Password")),
         new ProviderParameter("FtpSecure", FtpSecure.ToString(), GetConfigKey("FtpSecure")),
         new ProviderParameter("AcceptAnyTlsHostCertificate", AcceptAnyTlsHostCertificate.ToString(CultureInfo.InvariantCulture), GetConfigKey("AcceptAnyTlsHostCertificate")),
         new ProviderParameter("AcceptAnySshHostKey", AcceptAnySshHostKey.ToString(CultureInfo.InvariantCulture), GetConfigKey("AcceptAnySshHostKey")),
         new ProviderParameter("SshHostKeyFingerprint", SshHostKeyFingerprint, GetConfigKey("SshHostKeyFingerprint")),
         new ProviderParameter("SshPrivateKeyPassphrase", SecurityService.EncryptValue(SshPrivateKeyPassphrase), GetConfigKey("SshPrivateKeyPassphrase")),
         new ProviderParameter("SshPrivateKeyPath", SshPrivateKeyPath, GetConfigKey("SshPrivateKeyPath"))
     });
 }
コード例 #5
0
ファイル: SFtpClient.cs プロジェクト: rocker8942/Utility
 // FTP-S connection
 public SFtpClient(string hostname, string username, string password, FtpSecure ftpSecure, int portNumber)
 {
     _sessionOptions = new SessionOptions
     {
         Protocol = Protocol.Ftp,
         HostName = hostname,
         UserName = username,
         Password = password,
         FtpSecure = ftpSecure,
         PortNumber = portNumber,
         GiveUpSecurityAndAcceptAnyTlsHostCertificate = true
     };
 }