当前位置: 首页>>代码示例>>C#>>正文


C# SftpClient.Connect方法代码示例

本文整理汇总了C#中SftpClient.Connect方法的典型用法代码示例。如果您正苦于以下问题:C# SftpClient.Connect方法的具体用法?C# SftpClient.Connect怎么用?C# SftpClient.Connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SftpClient的用法示例。


在下文中一共展示了SftpClient.Connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Test_Sftp_SynchronizeDirectories

        public void Test_Sftp_SynchronizeDirectories()
        {
            RemoveAllFiles();

            using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
            {
                sftp.Connect();

                string uploadedFileName = Path.GetTempFileName();

                string sourceDir = Path.GetDirectoryName(uploadedFileName);
                string destDir = "/";
                string searchPattern = Path.GetFileName(uploadedFileName);
                var upLoadedFiles = sftp.SynchronizeDirectories(sourceDir, destDir, searchPattern);

                Assert.IsTrue(upLoadedFiles.Count() > 0);

                foreach (var file in upLoadedFiles)
                {
                    Debug.WriteLine(file.FullName);
                }

                sftp.Disconnect();
            }
        }
开发者ID:delfinof,项目名称:ssh.net,代码行数:25,代码来源:SftpClientTest.SynchronizeDirectories.cs

示例2: Arrange

        protected void Arrange()
        {
            _serviceFactoryMock = new Mock<IServiceFactory>(MockBehavior.Loose);
            _sessionMock = new Mock<ISession>(MockBehavior.Strict);
            _sftpSessionMock = new Mock<ISftpSession>(MockBehavior.Strict);

            _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth"));
            _operationTimeout = TimeSpan.FromSeconds(new Random().Next(1, 10));
            _sftpClient = new SftpClient(_connectionInfo, false, _serviceFactoryMock.Object);
            _sftpClient.OperationTimeout = _operationTimeout;

            _serviceFactoryMock.Setup(p => p.CreateSession(_connectionInfo))
                .Returns(_sessionMock.Object);
            _sessionMock.Setup(p => p.Connect());
            _serviceFactoryMock.Setup(p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding))
                .Returns(_sftpSessionMock.Object);
            _sftpSessionMock.Setup(p => p.Connect());

            _sftpClient.Connect();
            _sftpClient = null;

            _serviceFactoryMock.Setup(p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding))
                .Returns((ISftpSession)  null);
            _serviceFactoryMock.ResetCalls();

            // we need to dereference all other mocks as they might otherwise hold the target alive
            _sessionMock = null;
            _connectionInfo = null;
            _serviceFactoryMock = null;
        }
开发者ID:REALTOBIZ,项目名称:SSH.NET,代码行数:30,代码来源:SftpClientTest_Finalize_Connected.cs

示例3: Test_Sftp_Rename_File

        public void Test_Sftp_Rename_File()
        {
            using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
            {
                sftp.Connect();

                string uploadedFileName = Path.GetTempFileName();
                string remoteFileName1 = Path.GetRandomFileName();
                string remoteFileName2 = Path.GetRandomFileName();

                this.CreateTestFile(uploadedFileName, 1);

                using (var file = File.OpenRead(uploadedFileName))
                {
                    sftp.UploadFile(file, remoteFileName1);
                }

                sftp.RenameFile(remoteFileName1, remoteFileName2);

                File.Delete(uploadedFileName);

                sftp.Disconnect();
            }

            RemoveAllFiles();
        }
开发者ID:REALTOBIZ,项目名称:SSH.NET,代码行数:26,代码来源:SftpClientTest.RenameFile.cs

示例4: Test_KeyboardInteractiveConnectionInfo

        public void Test_KeyboardInteractiveConnectionInfo()
        {
            var host = Resources.HOST;
            var username = Resources.USERNAME;
            var password = Resources.PASSWORD;

            #region Example KeyboardInteractiveConnectionInfo AuthenticationPrompt
            var connectionInfo = new KeyboardInteractiveConnectionInfo(host, username);
            connectionInfo.AuthenticationPrompt += delegate(object sender, AuthenticationPromptEventArgs e)
            {
                System.Console.WriteLine(e.Instruction);

                foreach (var prompt in e.Prompts)
                {
                    Console.WriteLine(prompt.Request);
                    prompt.Response = Console.ReadLine();
                }
            };

            using (var client = new SftpClient(connectionInfo))
            {
                client.Connect();
                //  Do something here
                client.Disconnect();
            }
            #endregion

            Assert.AreEqual(connectionInfo.Host, Resources.HOST);
            Assert.AreEqual(connectionInfo.Username, Resources.USERNAME);
        }
开发者ID:REALTOBIZ,项目名称:SSH.NET,代码行数:30,代码来源:KeyboardInteractiveConnectionInfoTest.cs

示例5: Test_Sftp_SftpFile_MoveTo

        public void Test_Sftp_SftpFile_MoveTo()
        {
            using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
            {
                sftp.Connect();

                string uploadedFileName = Path.GetTempFileName();
                string remoteFileName = Path.GetRandomFileName();
                string newFileName = Path.GetRandomFileName();

                this.CreateTestFile(uploadedFileName, 1);

                using (var file = File.OpenRead(uploadedFileName))
                {
                    sftp.UploadFile(file, remoteFileName);
                }

                var sftpFile = sftp.Get(remoteFileName);

                sftpFile.MoveTo(newFileName);

                Assert.AreEqual(newFileName, sftpFile.Name);

                sftp.Disconnect();
            }
        }
开发者ID:nahidupa,项目名称:localtunnel-net-client,代码行数:26,代码来源:SftpFileTest.cs

示例6: Arrange

        protected void Arrange()
        {
            _serviceFactoryMock = new Mock<IServiceFactory>(MockBehavior.Strict);
            _sessionMock = new Mock<ISession>(MockBehavior.Strict);
            _sftpSessionMock = new Mock<ISftpSession>(MockBehavior.Strict);

            _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth"));
            _operationTimeout = TimeSpan.FromSeconds(new Random().Next(1, 10));
            _sftpClient = new SftpClient(_connectionInfo, false, _serviceFactoryMock.Object);
            _sftpClient.OperationTimeout = _operationTimeout;

            var sequence = new MockSequence();
            _serviceFactoryMock.InSequence(sequence)
                .Setup(p => p.CreateSession(_connectionInfo))
                .Returns(_sessionMock.Object);
            _sessionMock.InSequence(sequence).Setup(p => p.Connect());
            _serviceFactoryMock.InSequence(sequence)
                .Setup(p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding))
                .Returns(_sftpSessionMock.Object);
            _sftpSessionMock.InSequence(sequence).Setup(p => p.Connect());
            _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting());
            _sftpSessionMock.InSequence(sequence).Setup(p => p.Disconnect());
            _sftpSessionMock.InSequence(sequence).Setup(p => p.Dispose());
            _sessionMock.InSequence(sequence).Setup(p => p.Disconnect());
            _sessionMock.InSequence(sequence).Setup(p => p.Dispose());

            _sftpClient.Connect();
            _sftpClient.Disconnect();
        }
开发者ID:REALTOBIZ,项目名称:SSH.NET,代码行数:29,代码来源:SftpClientTest_Dispose_Disconnected.cs

示例7: Test_Sftp_ChangeDirectory_Root_Dont_Exists

 public void Test_Sftp_ChangeDirectory_Root_Dont_Exists()
 {
     using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
     {
         sftp.Connect();
         sftp.ChangeDirectory("/asdasd");
     }
 }
开发者ID:nahidupa,项目名称:localtunnel-net-client,代码行数:8,代码来源:ChangeDirectory.cs

示例8: Test_Sftp_ChangeDirectory_Subfolder_With_Slash_Dont_Exists

 public void Test_Sftp_ChangeDirectory_Subfolder_With_Slash_Dont_Exists()
 {
     using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
     {
         sftp.Connect();
         sftp.ChangeDirectory("/asdasd/sssddds/");
     }
 }
开发者ID:nahidupa,项目名称:localtunnel-net-client,代码行数:8,代码来源:ChangeDirectory.cs

示例9: Test_Sftp_BeginUploadFile_StreamIsNull

 public void Test_Sftp_BeginUploadFile_StreamIsNull()
 {
     using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
     {
         sftp.Connect();
         sftp.BeginUploadFile(null, "aaaaa", null, null);
         sftp.Disconnect();
     }
 }
开发者ID:pecegit,项目名称:sshnet,代码行数:9,代码来源:SftpClientTest.Upload.cs

示例10: Test_Sftp_BeginUploadFile_FileNameIsWhiteSpace

 public void Test_Sftp_BeginUploadFile_FileNameIsWhiteSpace()
 {
     using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
     {
         sftp.Connect();
         sftp.BeginUploadFile(new MemoryStream(), "   ", null, null);
         sftp.Disconnect();
     }
 }
开发者ID:pecegit,项目名称:sshnet,代码行数:9,代码来源:SftpClientTest.Upload.cs

示例11: Test_Get_Invalid_Directory

        public void Test_Get_Invalid_Directory()
        {
            using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
            {
                sftp.Connect();

                sftp.Get("/xyz");
            }
        }
开发者ID:nahidupa,项目名称:localtunnel-net-client,代码行数:9,代码来源:GetTest.cs

示例12: Test_Sftp_ChangeDirectory_Which_Exists

 public void Test_Sftp_ChangeDirectory_Which_Exists()
 {
     using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
     {
         sftp.Connect();
         sftp.ChangeDirectory("/usr");
         Assert.AreEqual("/usr", sftp.WorkingDirectory);
     }
 }
开发者ID:nahidupa,项目名称:localtunnel-net-client,代码行数:9,代码来源:ChangeDirectory.cs

示例13: Test_Sftp_Call_EndListDirectory_Twice

 public void Test_Sftp_Call_EndListDirectory_Twice()
 {
     using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
     {
         sftp.Connect();
         var ar = sftp.BeginListDirectory("/", null, null);
         var result = sftp.EndListDirectory(ar);
         var result1 = sftp.EndListDirectory(ar);
     }
 }
开发者ID:nahidupa,项目名称:localtunnel-net-client,代码行数:10,代码来源:ListDirectoryTest.cs

示例14: Test_Sftp_CreateDirectory_In_Current_Location

        public void Test_Sftp_CreateDirectory_In_Current_Location()
        {
            using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
            {
                sftp.Connect();

                sftp.CreateDirectory("test");

                sftp.Disconnect();
            }
        }
开发者ID:REALTOBIZ,项目名称:SSH.NET,代码行数:11,代码来源:SftpClientTest.CreateDirectory.cs

示例15: Test_Sftp_ChangeDirectory_Null

        public void Test_Sftp_ChangeDirectory_Null()
        {
            using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
            {
                sftp.Connect();

                sftp.ChangeDirectory(null);

                sftp.Disconnect();
            }
        }
开发者ID:nahidupa,项目名称:localtunnel-net-client,代码行数:11,代码来源:ListDirectoryTest.cs


注:本文中的SftpClient.Connect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。