本文整理汇总了C#中SftpClient类的典型用法代码示例。如果您正苦于以下问题:C# SftpClient类的具体用法?C# SftpClient怎么用?C# SftpClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SftpClient类属于命名空间,在下文中一共展示了SftpClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test_Sftp_SynchronizeDirectories
public void Test_Sftp_SynchronizeDirectories()
{
RemoveAllFiles();
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
{
sftp.Connect();
string uploadedFileName = Path.GetTempFileName();
string sourceDir = Path.GetDirectoryName(uploadedFileName);
string destDir = "/";
string searchPattern = Path.GetFileName(uploadedFileName);
var upLoadedFiles = sftp.SynchronizeDirectories(sourceDir, destDir, searchPattern);
Assert.IsTrue(upLoadedFiles.Count() > 0);
foreach (var file in upLoadedFiles)
{
Debug.WriteLine(file.FullName);
}
sftp.Disconnect();
}
}
示例2: Arrange
protected void Arrange()
{
_serviceFactoryMock = new Mock<IServiceFactory>(MockBehavior.Loose);
_sessionMock = new Mock<ISession>(MockBehavior.Strict);
_sftpSessionMock = new Mock<ISftpSession>(MockBehavior.Strict);
_connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth"));
_operationTimeout = TimeSpan.FromSeconds(new Random().Next(1, 10));
_sftpClient = new SftpClient(_connectionInfo, false, _serviceFactoryMock.Object);
_sftpClient.OperationTimeout = _operationTimeout;
_serviceFactoryMock.Setup(p => p.CreateSession(_connectionInfo))
.Returns(_sessionMock.Object);
_sessionMock.Setup(p => p.Connect());
_serviceFactoryMock.Setup(p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding))
.Returns(_sftpSessionMock.Object);
_sftpSessionMock.Setup(p => p.Connect());
_sftpClient.Connect();
_sftpClient = null;
_serviceFactoryMock.Setup(p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding))
.Returns((ISftpSession) null);
_serviceFactoryMock.ResetCalls();
// we need to dereference all other mocks as they might otherwise hold the target alive
_sessionMock = null;
_connectionInfo = null;
_serviceFactoryMock = null;
}
示例3: Arrange
protected void Arrange()
{
_serviceFactoryMock = new Mock<IServiceFactory>(MockBehavior.Strict);
_sessionMock = new Mock<ISession>(MockBehavior.Strict);
_sftpSessionMock = new Mock<ISftpSession>(MockBehavior.Strict);
_connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth"));
_operationTimeout = TimeSpan.FromSeconds(new Random().Next(1, 10));
_sftpClient = new SftpClient(_connectionInfo, false, _serviceFactoryMock.Object);
_sftpClient.OperationTimeout = _operationTimeout;
var sequence = new MockSequence();
_serviceFactoryMock.InSequence(sequence)
.Setup(p => p.CreateSession(_connectionInfo))
.Returns(_sessionMock.Object);
_sessionMock.InSequence(sequence).Setup(p => p.Connect());
_serviceFactoryMock.InSequence(sequence)
.Setup(p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding))
.Returns(_sftpSessionMock.Object);
_sftpSessionMock.InSequence(sequence).Setup(p => p.Connect());
_sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting());
_sftpSessionMock.InSequence(sequence).Setup(p => p.Disconnect());
_sftpSessionMock.InSequence(sequence).Setup(p => p.Dispose());
_sessionMock.InSequence(sequence).Setup(p => p.Disconnect());
_sessionMock.InSequence(sequence).Setup(p => p.Dispose());
_sftpClient.Connect();
_sftpClient.Disconnect();
}
示例4: Test_Sftp_CreateDirectory_Without_Connecting
public void Test_Sftp_CreateDirectory_Without_Connecting()
{
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
{
sftp.CreateDirectory("test");
}
}
示例5: SftpClientConstructorTest
[Ignore] // placeholder for actual test
public void SftpClientConstructorTest()
{
string host = string.Empty; // TODO: Initialize to an appropriate value
string username = string.Empty; // TODO: Initialize to an appropriate value
PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value
SftpClient target = new SftpClient(host, username, keyFiles);
Assert.Inconclusive("TODO: Implement code to verify target");
}
示例6: Test_Sftp_DeleteFile_Null
public void Test_Sftp_DeleteFile_Null()
{
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
{
sftp.DeleteFile(null);
}
}
示例7: 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();
}
}
示例8: 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();
}
示例9: Test_KeyboardInteractiveConnectionInfo
public void Test_KeyboardInteractiveConnectionInfo()
{
var host = Resources.HOST;
var username = Resources.USERNAME;
var password = Resources.PASSWORD;
#region Example KeyboardInteractiveConnectionInfo AuthenticationPrompt
var connectionInfo = new KeyboardInteractiveConnectionInfo(host, username);
connectionInfo.AuthenticationPrompt += delegate(object sender, AuthenticationPromptEventArgs e)
{
System.Console.WriteLine(e.Instruction);
foreach (var prompt in e.Prompts)
{
Console.WriteLine(prompt.Request);
prompt.Response = Console.ReadLine();
}
};
using (var client = new SftpClient(connectionInfo))
{
client.Connect();
// Do something here
client.Disconnect();
}
#endregion
Assert.AreEqual(connectionInfo.Host, Resources.HOST);
Assert.AreEqual(connectionInfo.Username, Resources.USERNAME);
}
示例10: Test_Sftp_ChangeDirectory_Subfolder_With_Slash_Dont_Exists
public void Test_Sftp_ChangeDirectory_Subfolder_With_Slash_Dont_Exists()
{
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
{
sftp.Connect();
sftp.ChangeDirectory("/asdasd/sssddds/");
}
}
示例11: Test_Sftp_ChangeDirectory_Root_Dont_Exists
public void Test_Sftp_ChangeDirectory_Root_Dont_Exists()
{
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
{
sftp.Connect();
sftp.ChangeDirectory("/asdasd");
}
}
示例12: SftpClientConstructorTest2
[Ignore] // placeholder for actual test
public void SftpClientConstructorTest2()
{
string host = string.Empty; // TODO: Initialize to an appropriate value
string username = string.Empty; // TODO: Initialize to an appropriate value
string password = string.Empty; // TODO: Initialize to an appropriate value
SftpClient target = new SftpClient(host, username, password);
Assert.Inconclusive("TODO: Implement code to verify target");
}
示例13: Test_Sftp_ChangeDirectory_Which_Exists
public void Test_Sftp_ChangeDirectory_Which_Exists()
{
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
{
sftp.Connect();
sftp.ChangeDirectory("/usr");
Assert.AreEqual("/usr", sftp.WorkingDirectory);
}
}
示例14: AppendAllTextTest
public void AppendAllTextTest()
{
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
string contents = string.Empty; // TODO: Initialize to an appropriate value
target.AppendAllText(path, contents);
Assert.Inconclusive("A method that does not return a value cannot be verified.");
}
示例15: Test_Get_Invalid_Directory
public void Test_Get_Invalid_Directory()
{
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
{
sftp.Connect();
sftp.Get("/xyz");
}
}