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