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


C# SftpClient.UploadFile方法代码示例

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


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

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

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

示例3: Test_Get_File

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

                sftp.UploadFile(new MemoryStream(), "abc.txt");

                var file = sftp.Get("abc.txt");

                Assert.AreEqual("/home/tester/abc.txt", file.FullName);
                Assert.IsTrue(file.IsRegularFile);
                Assert.IsFalse(file.IsDirectory);
            }
        }
开发者ID:nahidupa,项目名称:localtunnel-net-client,代码行数:15,代码来源:GetTest.cs

示例4: Test_Sftp_Upload_Forbidden

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

                string uploadedFileName = Path.GetTempFileName();
                string remoteFileName = "/root/1";

                this.CreateTestFile(uploadedFileName, 1);

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

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

示例5: Test_Sftp_Upload_And_Download_1MB_File

        public void Test_Sftp_Upload_And_Download_1MB_File()
        {
            RemoveAllFiles();

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

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

                this.CreateTestFile(uploadedFileName, 1);

                //  Calculate has value
                var uploadedHash = CalculateMD5(uploadedFileName);

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

                string downloadedFileName = Path.GetTempFileName();

                using (var file = File.OpenWrite(downloadedFileName))
                {
                    sftp.DownloadFile(remoteFileName, file);
                }

                var downloadedHash = CalculateMD5(downloadedFileName);

                sftp.DeleteFile(remoteFileName);

                File.Delete(uploadedFileName);
                File.Delete(downloadedFileName);

                sftp.Disconnect();

                Assert.AreEqual(uploadedHash, downloadedHash);
            }
        }
开发者ID:REALTOBIZ,项目名称:SSH.NET,代码行数:40,代码来源:SftpClientTest.Upload.cs

示例6: Test_Sftp_EndDownloadFile_Invalid_Async_Handle

 public void Test_Sftp_EndDownloadFile_Invalid_Async_Handle()
 {
     using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
     {
         sftp.Connect();
         var filename = Path.GetTempFileName();
         this.CreateTestFile(filename, 1);
         sftp.UploadFile(File.OpenRead(filename), "test123");
         var async1 = sftp.BeginListDirectory("/", null, null);
         var async2 = sftp.BeginDownloadFile("test123", new MemoryStream(), null, null);
         sftp.EndDownloadFile(async1);
     }
 }
开发者ID:REALTOBIZ,项目名称:SSH.NET,代码行数:13,代码来源:SftpClientTest.Download.cs

示例7: UploadFileTest1

 public void UploadFileTest1()
 {
     ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value
     SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value
     Stream input = null; // TODO: Initialize to an appropriate value
     string path = string.Empty; // TODO: Initialize to an appropriate value
     bool canOverride = false; // TODO: Initialize to an appropriate value
     Action<ulong> uploadCallback = null; // TODO: Initialize to an appropriate value
     target.UploadFile(input, path, canOverride, uploadCallback);
     Assert.Inconclusive("A method that does not return a value cannot be verified.");
 }
开发者ID:pecegit,项目名称:sshnet,代码行数:11,代码来源:SftpClientTest.cs


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