本文整理汇总了C#中SftpClient.EndDownloadFile方法的典型用法代码示例。如果您正苦于以下问题:C# SftpClient.EndDownloadFile方法的具体用法?C# SftpClient.EndDownloadFile怎么用?C# SftpClient.EndDownloadFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SftpClient
的用法示例。
在下文中一共展示了SftpClient.EndDownloadFile方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test_Sftp_Ensure_Async_Delegates_Called_For_BeginFileUpload_BeginFileDownload_BeginListDirectory
public void Test_Sftp_Ensure_Async_Delegates_Called_For_BeginFileUpload_BeginFileDownload_BeginListDirectory()
{
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
{
sftp.Connect();
string remoteFileName = Path.GetRandomFileName();
string localFileName = Path.GetRandomFileName();
bool uploadDelegateCalled = false;
bool downloadDelegateCalled = false;
bool listDirectoryDelegateCalled = false;
IAsyncResult asyncResult;
// Test for BeginUploadFile.
CreateTestFile(localFileName, 1);
using (var fileStream = File.OpenRead(localFileName))
{
asyncResult = sftp.BeginUploadFile(fileStream, remoteFileName, delegate(IAsyncResult ar)
{
sftp.EndUploadFile(ar);
uploadDelegateCalled = true;
}, null);
while (!asyncResult.IsCompleted)
{
Thread.Sleep(500);
}
}
File.Delete(localFileName);
Assert.IsTrue(uploadDelegateCalled, "BeginUploadFile");
// Test for BeginDownloadFile.
asyncResult = null;
using (var fileStream = File.OpenWrite(localFileName))
{
asyncResult = sftp.BeginDownloadFile(remoteFileName, fileStream, delegate(IAsyncResult ar)
{
sftp.EndDownloadFile(ar);
downloadDelegateCalled = true;
}, null);
while (!asyncResult.IsCompleted)
{
Thread.Sleep(500);
}
}
File.Delete(localFileName);
Assert.IsTrue(downloadDelegateCalled, "BeginDownloadFile");
// Test for BeginListDirectory.
asyncResult = null;
asyncResult = sftp.BeginListDirectory(sftp.WorkingDirectory, delegate(IAsyncResult ar)
{
sftp.EndListDirectory(ar);
listDirectoryDelegateCalled = true;
}, null);
while (!asyncResult.IsCompleted)
{
Thread.Sleep(500);
}
Assert.IsTrue(listDirectoryDelegateCalled, "BeginListDirectory");
}
}
示例2: Test_Sftp_Multiple_Async_Upload_And_Download_10Files_5MB_Each
//.........这里部分代码省略.........
uploadCompleted = true;
foreach (var testInfo in testInfoList.Values)
{
var sftpResult = testInfo.UploadResult;
if (!testInfo.UploadResult.IsCompleted)
{
uploadCompleted = false;
}
}
Thread.Sleep(500);
}
// End file uploads
foreach (var remoteFile in testInfoList.Keys)
{
var testInfo = testInfoList[remoteFile];
sftp.EndUploadFile(testInfo.UploadResult);
testInfo.UploadedFile.Dispose();
}
// Start file downloads
var downloadWaitHandles = new List<WaitHandle>();
foreach (var remoteFile in testInfoList.Keys)
{
var testInfo = testInfoList[remoteFile];
testInfo.DownloadedFile = File.OpenWrite(testInfo.DownloadedFileName);
testInfo.DownloadResult = sftp.BeginDownloadFile(remoteFile,
testInfo.DownloadedFile,
null,
null) as SftpDownloadAsyncResult;
downloadWaitHandles.Add(testInfo.DownloadResult.AsyncWaitHandle);
}
// Wait for download to finish
bool downloadCompleted = false;
while (!downloadCompleted)
{
// Assume download completed
downloadCompleted = true;
foreach (var testInfo in testInfoList.Values)
{
var sftpResult = testInfo.DownloadResult;
if (!testInfo.DownloadResult.IsCompleted)
{
downloadCompleted = false;
}
}
Thread.Sleep(500);
}
var hashMatches = true;
var uploadDownloadSizeOk = true;
// End file downloads
foreach (var remoteFile in testInfoList.Keys)
{
var testInfo = testInfoList[remoteFile];
sftp.EndDownloadFile(testInfo.DownloadResult);
testInfo.DownloadedFile.Dispose();
testInfo.DownloadedHash = CalculateMD5(testInfo.DownloadedFileName);
if (!(testInfo.UploadResult.UploadedBytes > 0 && testInfo.DownloadResult.DownloadedBytes > 0 && testInfo.DownloadResult.DownloadedBytes == testInfo.UploadResult.UploadedBytes))
{
uploadDownloadSizeOk = false;
}
if (!testInfo.DownloadedHash.Equals(testInfo.UploadedHash))
{
hashMatches = false;
}
}
// Clean up after test
foreach (var remoteFile in testInfoList.Keys)
{
var testInfo = testInfoList[remoteFile];
sftp.DeleteFile(remoteFile);
File.Delete(testInfo.UploadedFileName);
File.Delete(testInfo.DownloadedFileName);
}
sftp.Disconnect();
Assert.IsTrue(hashMatches, "Hash does not match");
Assert.IsTrue(uploadDownloadSizeOk, "Uploaded and downloaded bytes does not match");
}
}
示例3: 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);
}
}
示例4: DownloadFilesFromServer
private void DownloadFilesFromServer()
{
try
{
var filelist = new Dictionary<SftpFile, string>();
var remfold = txtRemoteFolderPath.Text.EndsWith("/") ? txtRemoteFolderPath.Text : txtRemoteFolderPath.Text += "/";
var ssh = new SftpClient(txtHost.Text, int.Parse(txtPort.Text), txtUser.Text, txtPassword.Text);
ssh.Connect();
foreach (var i in lvSSHFileBrowser.SelectedItems.Cast<EXImageListViewItem>().Select(item => item.Tag as SftpFile))
{
if (i.IsRegularFile)
{
filelist.Add(i, Path.Combine(txtLocalBrowserPath.Text, i.Name));
}
if (i.IsDirectory)
{
foreach (var file in GetFilesRecur(ssh, i))
{
var i1 = file.FullName.Replace(remfold, "");
var i2 = i1.Replace('/', '\\');
var i3 = Path.Combine(txtLocalBrowserPath.Text, i2);
filelist.Add(file, i3);
}
}
}
long totalsize = filelist.Sum(pair => pair.Key.Length);
var result = MessageBox.Show(string.Format(Language.SSHTransfer_DownloadFilesFromServer_Download__0__in__1__files_ + "\r\n" + Language.SSHTransfer_DownloadFilesFromServer_Destination_directory__2_, Tools.Misc.LengthToHumanReadable(totalsize), filelist.Count, txtLocalBrowserPath.Text), "Downloading", MessageBoxButtons.YesNoCancel);
if (result!=DialogResult.Yes)
{
EnableButtons();
return;
}
long totaluploaded = 0;
ThreadPool.QueueUserWorkItem(state =>
{
foreach (var file in filelist)
{
if (!Directory.Exists(Path.GetDirectoryName(file.Value)))
{
Tools.Misc.ebfFolderCreate(Path.GetDirectoryName(file.Value));
}
var asynch = ssh.BeginDownloadFile(file.Key.FullName,
new FileStream(file.Value, FileMode.Create));
var sftpAsynch = asynch as SftpDownloadAsyncResult;
while (!sftpAsynch.IsCompleted)
{
SetProgressStatus(totaluploaded + (long)sftpAsynch.DownloadedBytes, totalsize);
}
totaluploaded += file.Key.Length;
ssh.EndDownloadFile(asynch);
}
EnableButtons();
ssh.Disconnect();
MessageBox.Show(Language.SSHTransfer_DownloadFilesFromServer_Download_finished);
});
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
示例5: EndDownloadFileTest
public void EndDownloadFileTest()
{
ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value
SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value
IAsyncResult asyncResult = null; // TODO: Initialize to an appropriate value
target.EndDownloadFile(asyncResult);
Assert.Inconclusive("A method that does not return a value cannot be verified.");
}