Test.SFTP.Server
1.0.0
dotnet add package Test.SFTP.Server --version 1.0.0
NuGet\Install-Package Test.SFTP.Server -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Test.SFTP.Server" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Test.SFTP.Server --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Test.SFTP.Server, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Test.SFTP.Server as a Cake Addin #addin nuget:?package=Test.SFTP.Server&version=1.0.0 // Install Test.SFTP.Server as a Cake Tool #tool nuget:?package=Test.SFTP.Server&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
using System;
using System.IO;
using System.Text;
using Test.SFTP.Server.CeSftpServer;
using FluentAssertions;
using NUnit.Framework;
using Renci.SshNet;
namespace MM.Test.PluginCore.Common;
public class CeSftpServerTest
{
const string USERNAME = "user@domain.com";
const string PASSWORD = "1234";
private readonly CeSftpServer _sftpServer;
public CeSftpServerTest() => _sftpServer = CeSftpServer.Instance;
[Test]
public void Should_Connect_To_Sftp_Auth_Type_Password()
{
// run the sftp server
_sftpServer.Start();
using var sshClient = new SshClient(GetConnectionInfo(new PasswordAuthenticationMethod(USERNAME, PASSWORD)));
sshClient.Connect();
sshClient.IsConnected.Should().Be(true);
_sftpServer.Dispose();
}
[Test]
public void Should_Connect_To_Sftp_Auth_Type_Private_Key()
{
var pk = new PrivateKeyFile(SshKeyHelper.GetPrivateKeyStream());
var keyFiles = new[] { pk };
// run the sftp server
_sftpServer.Start();
using var sshClient = new SshClient(GetConnectionInfo(new PrivateKeyAuthenticationMethod(USERNAME, keyFiles)));
sshClient.Connect();
sshClient.IsConnected.Should().Be(true);
_sftpServer.Dispose();
}
/// <summary>
/// Renci.SshNet only accept private keys
/// NOTE: Renci.SshNet does not support OpenSSH keys
/// </summary>
[Test]
public void Should_Fail_To_Connect_To_Sftp_Auth_Type_Public_Key()
{
var pk = new PrivateKeyFile(SshKeyHelper.GetPrivateKeyStream());
var keyFiles = new[] { pk };
// run the sftp server
_sftpServer.Start();
Assert.Throws<ArgumentException>(() =>
{
var unused = new SshClient(GetConnectionInfo(new PrivateKeyAuthenticationMethod("", keyFiles), ""));
});
_sftpServer.Dispose();
}
[Test]
[Explicit("This is the upload sample and it should run locally")]
public void Should_Upload_Files()
{
// run the sftp server
_sftpServer.Start();
using var sftpClient = new SftpClient(_sftpServer.IpAddress.ToString(),_sftpServer.Port, USERNAME, PASSWORD);
sftpClient.Connect();
const string FILE_PATH = @"C:\sftp\Upload\file.txt";
var ms = new MemoryStream(Encoding.UTF8.GetBytes("test"));
ms.Seek(0, SeekOrigin.Begin);
// it should upload the file.txt in C:\sftp\Upload\file.txt (the default home dir _sftpServer is C:\sftp)
sftpClient.UploadFile(ms, "Upload/file.txt");
File.Exists(FILE_PATH).Should().Be(true);
_sftpServer.Dispose();
}
[Test]
[Explicit("This is the download sample, and it should run locally.")]
public void Should_Download_Files()
{
// run the sftp server
_sftpServer.Start();
using var sftpClient = new SftpClient(_sftpServer.IpAddress.ToString(),_sftpServer.Port, USERNAME, PASSWORD);
sftpClient.Connect();
const string FILE_PATH = @"C:\sftp\Downloaded\downloaded.txt";
using (Stream fileStream = File.Create(FILE_PATH))
{
// it should download the file.txt from C:\sftp\Download\Download.txt (the default home dir _sftpServer is C:\sftp)
sftpClient.DownloadFile(@"Download/Download.txt", fileStream);
}
File.Exists(FILE_PATH).Should().Be(true);
_sftpServer.Dispose();
}
private ConnectionInfo GetConnectionInfo(AuthenticationMethod authenticationMethod, string username = USERNAME) =>
new(_sftpServer.IpAddress.ToString(), _sftpServer.Port, username, authenticationMethod);
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- FxSsh (>= 1.2.0)
- SshKeyGenerator (>= 1.1.51)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 268 | 2/1/2023 |