本文整理汇总了C#中SftpClient.Disconnect方法的典型用法代码示例。如果您正苦于以下问题:C# SftpClient.Disconnect方法的具体用法?C# SftpClient.Disconnect怎么用?C# SftpClient.Disconnect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SftpClient
的用法示例。
在下文中一共展示了SftpClient.Disconnect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: 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();
}
}
示例3: 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();
}
}
示例4: 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();
}
示例5: 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();
}
示例6: Test_Sftp_BeginUploadFile_StreamIsNull
public void Test_Sftp_BeginUploadFile_StreamIsNull()
{
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
{
sftp.Connect();
sftp.BeginUploadFile(null, "aaaaa", null, null);
sftp.Disconnect();
}
}
示例7: Test_Sftp_BeginUploadFile_FileNameIsWhiteSpace
public void Test_Sftp_BeginUploadFile_FileNameIsWhiteSpace()
{
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
{
sftp.Connect();
sftp.BeginUploadFile(new MemoryStream(), " ", null, null);
sftp.Disconnect();
}
}
示例8: Test_Sftp_ChangeDirectory_Null
public void Test_Sftp_ChangeDirectory_Null()
{
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
{
sftp.Connect();
sftp.ChangeDirectory(null);
sftp.Disconnect();
}
}
示例9: Test_Sftp_CreateDirectory_Invalid_Path
public void Test_Sftp_CreateDirectory_Invalid_Path()
{
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
{
sftp.Connect();
sftp.CreateDirectory("/abcdefg/abcefg");
sftp.Disconnect();
}
}
示例10: Test_Get_File_Null
public void Test_Get_File_Null()
{
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
{
sftp.Connect();
var file = sftp.Get(null);
sftp.Disconnect();
}
}
示例11: Test_Sftp_CreateDirectory_In_Current_Location
public void Test_Sftp_CreateDirectory_In_Current_Location()
{
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
{
sftp.Connect();
sftp.CreateDirectory("test");
sftp.Disconnect();
}
}
示例12: Test_Sftp_RenameFile_Null
public void Test_Sftp_RenameFile_Null()
{
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
{
sftp.Connect();
sftp.RenameFile(null, null);
sftp.Disconnect();
}
}
示例13: Test_Sftp_DeleteDirectory_Which_Doesnt_Exists
public void Test_Sftp_DeleteDirectory_Which_Doesnt_Exists()
{
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
{
sftp.Connect();
sftp.DeleteDirectory("abcdef");
sftp.Disconnect();
}
}
示例14: Test_Sftp_CreateDirectory_Already_Exists
public void Test_Sftp_CreateDirectory_Already_Exists()
{
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
{
sftp.Connect();
sftp.CreateDirectory("test");
sftp.CreateDirectory("test");
sftp.Disconnect();
}
}
示例15: Test_Sftp_CreateDirectory_In_Forbidden_Directory
public void Test_Sftp_CreateDirectory_In_Forbidden_Directory()
{
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();
sftp.CreateDirectory("/sbin/test");
sftp.Disconnect();
}
}