github sshnet/SSH.NET 2016.1.0-beta3

latest releases: 2024.2.0, 2024.1.0, 2024.0.0...
pre-release7 years ago

Changes

ScpClient

A RemotePathTransformation property has been added to ScpClient that can be used to change if and how a remote path is transformed before it is passed to the scp command on the remote server.

SSH.NET comes with the following path transformations that are exposed through the RemotePathTransformation class (in Renci.SshNet):

  • DoubleQuote
    Encloses a path in double quotes, and escapes any embedded double quote with a backslash.
    This is the default, as it works fine with most SCP servers.

  • ShellQuote
    Quotes a path in a way to be suitable to be used with a shell-based SCP server.
    This is the preferred mechanism for shell-based SCP servers, which typically means all Unix-like systems.

  • None
    Performs no transformation to the path.
    This is the recommended transformation when the remote host does not require any quoting to preserve the literal value of metacharacters, or when remote paths are guaranteed not to contain such characters.

When none of the built-in transformations match the specific requirements of a remote host, a custom transformation can be supplied.

More information on this change is available here.

Fixes issues #256 and #108.

Example:

Download a file using SCP, and apply shell quoting to the remote path:

using Renci.SshNet;

public class Program
{
  static void Main()
  {
      using (var client = new ScpClient("HOST", 22, "USER", "PWD"))
      {
          client.RemotePathTransformation = RemotePathTransformation.ShellQuote;
          client.Connect();

          using (var ms = new MemoryStream())
          {
              client.Download("/home/sshnet/file 123", ms);
          }
      }
  }
}

Since we've configured ScpClient to use the ShellQuote transformation, the /home/sshnet/file 123 path
will automatically be enclosed in single quotes.

The actual path that is passed to the scp command on the remote host is therefore '/home/sshnet/file 123'.

Breaking changes

ScpClient

The Upload(FileInfo fileInfo, String path) method in ScpClient now expects path to be the remote path of the file to which you want to upload, and throws a ScpException if a directory exists on the remote host for that path (issue #286).

Up until now, uploading a file with a given (remote) path could lead a different result depending on whether a directory for that path exits on the remote host.

Example:

  using (var client = new ScpClient("host", "user", "pwd"))
  {
      client.Connect();

      client.Upload(new FileInfo(@"c:\temp\newlog.txt", "/home/sshnet/log");
  }

As of version 2016.1.0-beta3 a ScpException will be thrown when /home/sshnet/log exists as a directory on the remote host.

In previous versions of SSH.NET this code would actually upload the content of the c:\temp\newlog.txt file to /home/sshnet/log/newlog.txt.

When /home/sshnet/log exists on the remote host as a file or does not exist at all, the content of the c:\temp\newlog.txt file will be uploaded to /home/sshnet/log. This has not changed.

Fixes

ScpClient

  • Upload(Stream source, String path) does not support uploading a file to the home directory using a relative path (issue #280).

    The following code will now just work:

    using (var client = new ScpClient("host", "user", "pwd"))
    {
        client.Connect();
    
        using (var fs = File.OpenRead(@"c:\file.log"))
        {
            client.Upload(fs, "file.log");
        }
    }
  • Upload(Stream source, String path) does not throw an exception when parent directory does not exist (issue #289).

  • ScpClient does not support non-ASCII characters in downloaded file names or error message (issue #281).

SftpClient

  • DowloadFile(String path, Stream output, Action<UInt64>) does not perform well on Sun SSH (issue #292).

SshClient

  • ShellStream.Write(byte[] buffer, Int32 offset, Int32 count) skips a single byte when buffer is full (PR #211).
  • CreateShellStream overloads always use a 1024 byte buffer (issue #303)

Don't miss a new SSH.NET release

NewReleases is sending notifications on new releases.