namespace Renci.SshNet
{
///
/// Provides access to built-in remote path transformations.
///
///
/// References:
///
/// -
/// Shell Command Language
///
/// -
/// Unix C-Shell special characters and their uses
///
/// -
/// Differences Between Bourne and C Shell Quoting
///
/// -
/// Everyone quotes command line arguments the wrong way
///
///
///
public static class RemotePathTransformation
{
private static readonly IRemotePathTransformation ShellQuoteTransformation = new RemotePathShellQuoteTransformation();
private static readonly IRemotePathTransformation NoneTransformation = new RemotePathNoneTransformation();
private static readonly IRemotePathTransformation DoubleQuoteTransformation = new RemotePathDoubleQuoteTransformation();
///
/// Quotes a path in a way to be suitable to be used with a shell-based server.
///
///
/// A quoted path.
///
///
///
/// If a path contains a single-quote, that character is embedded in quotation marks (eg. "'").
/// Sequences of single-quotes are grouped in a single pair of quotation marks.
///
///
/// An exclamation mark in a path is escaped with a backslash. This is necessary because C Shell
/// interprets it as a meta-character for history substitution even when enclosed in single quotes
/// or quotation marks.
///
///
/// All other characters are enclosed in single quotes. Sequences of such characters are grouped
/// in a single pair of single quotes.
///
///
///
///
///
/// Original
/// Transformed
///
/// -
/// /var/log/auth.log
/// '/var/log/auth.log'
///
/// -
/// /var/mp3/Guns N' Roses
/// '/var/mp3/Guns N'"'"' Roses'
///
/// -
/// /var/garbage!/temp
/// '/var/garbage'\!'/temp'
///
/// -
/// /var/would be 'kewl'!, not?
/// '/var/would be '"'"'kewl'"'"\!', not?'
///
/// -
///
/// ''
///
/// -
/// Hello "World"
/// 'Hello "World"'
///
///
///
public static IRemotePathTransformation ShellQuote
{
get { return ShellQuoteTransformation; }
}
///
/// Performs no transformation.
///
///
/// Recommended for servers that do not require any character to be escaped or enclosed in quotes,
/// or when paths are guaranteed to never contain any special characters (such as #, ", ', $, ...).
///
public static IRemotePathTransformation None
{
get { return NoneTransformation; }
}
///
/// Encloses a path in double quotes, and escapes any embedded double quote with a backslash.
///
///
/// A transformation that encloses a path in double quotes, and escapes any embedded double quote with
/// a backslash.
///
///
///
///
/// Original
/// Transformed
///
/// -
/// /var/log/auth.log
/// "/var/log/auth.log"
///
/// -
/// /var/mp3/Guns N' Roses
/// "/var/mp3/Guns N' Roses"
///
/// -
/// /var/garbage!/temp
/// "/var/garbage!/temp"
///
/// -
/// /var/would be 'kewl'!, not?
/// "/var/would be 'kewl'!, not?"
///
/// -
///
/// ""
///
/// -
/// Hello "World"
/// "Hello \"World"
///
///
///
public static IRemotePathTransformation DoubleQuote
{
get { return DoubleQuoteTransformation; }
}
}
}