本文整理汇总了C#中SftpClient.DeleteFile方法的典型用法代码示例。如果您正苦于以下问题:C# SftpClient.DeleteFile方法的具体用法?C# SftpClient.DeleteFile怎么用?C# SftpClient.DeleteFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SftpClient
的用法示例。
在下文中一共展示了SftpClient.DeleteFile方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test_Sftp_DeleteFile_Null
public void Test_Sftp_DeleteFile_Null()
{
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
{
sftp.DeleteFile(null);
}
}
示例2: 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);
}
}
示例3: 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");
}
}
示例4: DeleteFileTest
public void DeleteFileTest()
{
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
target.DeleteFile(path);
Assert.Inconclusive("A method that does not return a value cannot be verified.");
}