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


C# SftpClient.DownloadFile方法代码示例

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


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

示例1: Test_Sftp_Download_File_Not_Exists

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

                string remoteFileName = "/xxx/eee/yyy";
                using (var ms = new MemoryStream())
                {
                    sftp.DownloadFile(remoteFileName, ms);
                }

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

示例2: Test_Sftp_Download_Forbidden

        public void Test_Sftp_Download_Forbidden()
        {
            if (Resources.USERNAME == "root")
                Assert.Fail("Must not run this test as root!");

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

                string remoteFileName = "/root/.profile";

                using (var ms = new MemoryStream())
                {
                    sftp.DownloadFile(remoteFileName, ms);
                }

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

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

示例4: getFromSFTP

        // get file from SFTP and return string
        public void getFromSFTP(string url)
        {
            try
            {
                myFileStream = new FileStream(@"\NVRAM\temp.txt", FileMode.Create);
                mySFTPClient = new SftpClient(url, 22, "Crestron", "");

                mySFTPClient.Connect();
                mySFTPClient.DownloadFile(url, myFileStream, DownloadDone);

                return;
            }
            catch (Exception e)
            {
                CrestronConsole.PrintLine("Exception {0}", e);
                return;
            }
            finally
            {
                mySFTPClient.Disconnect();
                myFileStream.Close();
            }
        }
开发者ID:RBSystems,项目名称:SIMPLSharp,代码行数:24,代码来源:ControlSystem.cs

示例5: getFromSFTP

            // get file from SFTP and return string
            public void getFromSFTP(string hostname, int port, string userName, string password, string tempFileName, string fileName)
            {
            try
            {
                mySFTPClient = new SftpClient(hostname, port, userName, password);
                myFileStream = new FileStream(tempFileName, FileMode.Create);

                mySFTPClient.Connect();
                mySFTPClient.DownloadFile(fileName, myFileStream, DownloadDone); // DownloadDone is Action<ulong>

                return;
            }
            catch (Exception e)
            {
                CrestronConsole.PrintLine("Document.getFromSFTP() Exception {0}", e);
                CrestronConsole.PrintLine("Document.getFromSFTP() Host {0}, Port {1}, User {2}, fileName {3}",
                                            hostname, port, userName, fileName);
                throw;
            }
            finally
            {
                mySFTPClient.Disconnect();
                myFileStream.Close();
            }
            }
开发者ID:RBSystems,项目名称:SIMPLSharp,代码行数:26,代码来源:ControlSystem.cs

示例6: OpenSFTPFile

            public ushort OpenSFTPFile(String strUser, String strPassword, String strHost, String strPath)
            {
                ushort returnvalue = 1;
                FileStream myStream;
                SftpClient myClient;
                try
                {
                    myStream = new FileStream(@"\nvram\temp.txt", FileMode.Create);
                    myClient = new SftpClient(strHost, 22, strUser, strPassword);
                    myClient.Connect();
                    //Action<ulong> myAction = DownloadDone; // Defines that myAction is a delegate that takes a single ulong input and is the same as the function download done.
                    myClient.DownloadFile(strPath, myStream, DownloadDone); // Replace DownloadDone with myAction if using.
                    myClient.Disconnect();
                    myStream.Close();
                }
                catch (Exception e)
                {
                    ErrorLog.Error(String.Format("Error Loading SFTP file: {0}", e.Message));
                    returnvalue = 0;
                }
                finally
                {
                    if (returnvalue == 1)
                        OpenLocalFile(@"\nvram\temp.txt");
                }

                return returnvalue;
            }
开发者ID:RBSystems,项目名称:SIMPLSharp,代码行数:28,代码来源:ControlSystem.cs

示例7: DownloadFileTest

 public void DownloadFileTest()
 {
     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
     Stream output = null; // TODO: Initialize to an appropriate value
     Action<ulong> downloadCallback = null; // TODO: Initialize to an appropriate value
     target.DownloadFile(path, output, downloadCallback);
     Assert.Inconclusive("A method that does not return a value cannot be verified.");
 }
开发者ID:pecegit,项目名称:sshnet,代码行数:10,代码来源:SftpClientTest.cs


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