Bodoconsult.Web.Ftp 1.0.11

dotnet add package Bodoconsult.Web.Ftp --version 1.0.11
                    
NuGet\Install-Package Bodoconsult.Web.Ftp -Version 1.0.11
                    
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="Bodoconsult.Web.Ftp" Version="1.0.11" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Bodoconsult.Web.Ftp" Version="1.0.11" />
                    
Directory.Packages.props
<PackageReference Include="Bodoconsult.Web.Ftp" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Bodoconsult.Web.Ftp --version 1.0.11
                    
#r "nuget: Bodoconsult.Web.Ftp, 1.0.11"
                    
#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.
#:package Bodoconsult.Web.Ftp@1.0.11
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Bodoconsult.Web.Ftp&version=1.0.11
                    
Install as a Cake Addin
#tool nuget:?package=Bodoconsult.Web.Ftp&version=1.0.11
                    
Install as a Cake Tool

What does the library

Bodoconsult.Web.Ftp library simplifies the access to FTP servers via SSH.

How to use the library

The source code contain a NUnit test classes, the following source code is extracted from. The samples below show the most helpful use cases for the library.

Overview

The main class in the library is the class SshHandler with the following methods:

  • Connect()
  • Disconnect()
  • Put(string localPath, string remotePath)
  • RemoveFile(string remotePath)
  • Exists(string path)
  • CreateDirectory(string remotePath)
  • RemoveDirectory(string remotePath)
  • GetDirectoryItems(string remotePath)
  • GetDirectoryItemsRaw(string remotePath)
  • DownloadFile(string remotePath, string localPath)

Samples

Connect to SSH server

[Test]
public void TestConnect()
{

	// Arrange
	var s = new SshHandler(_credentials);
				
	// Act
	s.Connect();

	var erg = s.IsConnected;

	s.Disconnect();

	// Assert
	Assert.That(erg);
}

Put a local directory as main directory to the remote server

[Test]
public void TestPutMainDirectory()
{

	// Arrange
	var localPath = TestHelper.FtpTestFilePath;

	const string remotePath = "/"+TestHelper.FtpTestFileName;

	var s = new SshHandler(_credentials);


	// Act
	s.Connect();

	var erg1 = s.IsConnected;

				
	s.Put(localPath, remotePath);

	s.Disconnect();

	// Assert
	Assert.That(erg1);
}

Put a local directory as subdirectory to the remote server

[Test]
public void TestPutDirectory()
{

	// Arrange
	var localPath = TestHelper.FtpTestFilePath;

	var remotePath = $"{TestHelper.FtpSubDir}/{TestHelper.FtpTestFileName}";

	var s = new SshHandler(_credentials);


	// Act
	s.Connect();

	var erg1 = s.IsConnected;


	s.Put(localPath, remotePath);

	s.Disconnect();

	// Assert
	Assert.That(erg1);
}

Remove a file on the remote server

[Test]
public void TestRemoveFile()
{

	// Arrange
	var localPath = TestHelper.FtpTestFilePath;

	var remotePath = $"{TestHelper.FtpSubDir}/{TestHelper.FtpTestFileName}";

	var s = new SshHandler(_credentials);


	// Act
	s.Connect();

	var erg1 = s.IsConnected;

	s.Put(localPath, remotePath);

	Assert.That(s.Exists(remotePath));

	// Act
	s.RemoveFile(remotePath);
	var erg2 = s.Exists(remotePath);
	s.Disconnect();

	// Assert
	Assert.That(erg1);
	Assert.That(!erg2);
}

Create a remote directory

[Test]
public void TestCreateDirectory()
{

	// Arrange
	var remotePath = TestHelper.FtpSubDirCreate;

	var s = new SshHandler(_credentials);


	// Act
	s.Connect();

	var erg1 = s.IsConnected;

	s.RemoveDirectory(remotePath);
	Assert.That(!s.Exists(remotePath));

	// Act
	s.CreateDirectory(remotePath);
	var erg2 = s.Exists(remotePath);
	s.Disconnect();

	// Assert
	Assert.That(erg1);
	Assert.That(erg2);
}

List remote directory content

[Test]
public void TestListDirectory()
{

	// Arrange
	const string remotePath = TestHelper.FtpSubDir;

	var remotePath1 = TestHelper.FtpSubDirCreate;

	var s = new SshHandler(_credentials);

	s.Connect();

	if (!s.Exists(remotePath1)) s.CreateDirectory(remotePath1);

	var erg1 = s.IsConnected;

	var localPath = TestHelper.FtpTestFilePath;

	var remotePathFile = $"{TestHelper.FtpSubDir}/{TestHelper.FtpTestFileName}";

	if (!s.Exists(remotePathFile)) s.Put(localPath, remotePathFile);

	// Act
	var erg2 = s.GetDirectoryItems(remotePath).ToList();

	s.Disconnect();

	// Assert
	Assert.That(erg1);
	Assert.That(erg2.Any());
	Assert.That(erg2.Any(x => x.IsDirectory));
	Assert.That(erg2.Any(x => !x.IsDirectory));
}

Download a remote file

[Test]
public void TestDownloadFile()
{

	// Arrange
	var remotePath = "/"+ TestHelper.FtpTestFileName;
	var localPath = Path.Combine(TestHelper.LocalTargetPath,"AAA.txt");

	var s = new SshHandler(_credentials);


	if (File.Exists(localPath))
	{
		File.Delete(localPath);
	}


	// Act
	s.Connect();

	var erg1 = s.IsConnected;

	// Act
	s.DownloadFile(remotePath, localPath);
	s.Disconnect();

	var erg2 = File.Exists(localPath);

	// Assert
	Assert.That(erg1);
	Assert.That(erg2);
}

Remove a remote directory

[Test]
public void TestRemoveDirectory()
{

	// Arrange
	var remotePath1 = TestHelper.FtpSubDirCreate;

	var s = new SshHandler(_credentials);

	s.Connect();

	if (!s.Exists(remotePath1)) s.CreateDirectory(remotePath1);

	var erg1 = s.IsConnected;

	// Act
	s.RemoveDirectory(remotePath1);

	// Assert
	var erg2 = s.Exists(remotePath1);

	s.Disconnect();

				
	Assert.That(erg1);
	Assert.That(!erg2);
}

About us

Bodoconsult (http://www.bodoconsult.de) is a Munich based software development company from Germany.

Robert Leisner is senior software developer at Bodoconsult. See his profile on http://www.bodoconsult.de/Curriculum_vitae_Robert_Leisner.pdf.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.11 94 11/2/2026
1.0.10 88 11/2/2026

Migration to .NET 8, updated dependencies and add README.md