• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# SftpClient类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



SftpClient类属于命名空间,在下文中一共展示了SftpClient类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: 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


示例4: Test_Sftp_CreateDirectory_Without_Connecting

 public void Test_Sftp_CreateDirectory_Without_Connecting()
 {
     using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
     {
         sftp.CreateDirectory("test");
     }
 }
开发者ID:REALTOBIZ,项目名称:SSH.NET,代码行数:7,代码来源:SftpClientTest.CreateDirectory.cs


示例5: Test_Sftp_DeleteFile_Null

 public void Test_Sftp_DeleteFile_Null()
 {
     using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
     {
         sftp.DeleteFile(null);
     }
 }
开发者ID:delfinof,项目名称:ssh.net,代码行数:7,代码来源:SftpClientTest.DeleteFile.cs


示例6: 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


示例7: 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


示例8: 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


示例9: SftpClientConstructorTest

 [Ignore] // placeholder for actual test
 public void SftpClientConstructorTest()
 {
     string host = string.Empty; // TODO: Initialize to an appropriate value
     string username = string.Empty; // TODO: Initialize to an appropriate value
     PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value
     SftpClient target = new SftpClient(host, username, keyFiles);
     Assert.Inconclusive("TODO: Implement code to verify target");
 }
开发者ID:delfinof,项目名称:ssh.net,代码行数:9,代码来源:SftpClientTest.cs


示例10: 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


示例11: 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


示例12: SftpClientConstructorTest2

 [Ignore] // placeholder for actual test
 public void SftpClientConstructorTest2()
 {
     string host = string.Empty; // TODO: Initialize to an appropriate value
     string username = string.Empty; // TODO: Initialize to an appropriate value
     string password = string.Empty; // TODO: Initialize to an appropriate value
     SftpClient target = new SftpClient(host, username, password);
     Assert.Inconclusive("TODO: Implement code to verify target");
 }
开发者ID:delfinof,项目名称:ssh.net,代码行数:9,代码来源:SftpClientTest.cs


示例13: 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


示例14: AppendAllTextTest

 public void AppendAllTextTest()
 {
     ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value
     SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value
     string path = string.Empty; // TODO: Initialize to an appropriate value
     string contents = string.Empty; // TODO: Initialize to an appropriate value
     target.AppendAllText(path, contents);
     Assert.Inconclusive("A method that does not return a value cannot be verified.");
 }
开发者ID:pecegit,项目名称:sshnet,代码行数:9,代码来源:SftpClientTest.cs


示例15: 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


示例16: 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


示例17: 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


示例18: AppendAllLinesTest1

 public void AppendAllLinesTest1()
 {
     ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value
     SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value
     string path = string.Empty; // TODO: Initialize to an appropriate value
     IEnumerable<string> contents = null; // TODO: Initialize to an appropriate value
     Encoding encoding = null; // TODO: Initialize to an appropriate value
     target.AppendAllLines(path, contents, encoding);
     Assert.Inconclusive("A method that does not return a value cannot be verified.");
 }
开发者ID:pecegit,项目名称:sshnet,代码行数:10,代码来源:SftpClientTest.cs


示例19: 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


示例20: Test_Get_File_Null

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

                var file = sftp.Get(null);

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Shader类代码示例发布时间:2022-05-24
下一篇:
C# Sex类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap