本文整理汇总了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();
}
}
示例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();
}
}
示例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);
}
}
示例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();
}
}
示例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();
}
}
示例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;
}
示例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.");
}