Home Forums .NET libraries Xceed SFTP/FTP for .NET SFtp capabilities and usage

Viewing 1 post (of 1 total)
  • Author
    Posts
  • Xceed Support
    Member
    Post count: 5658
    #21468 |

    SFtp
    stands for SSH File Transfer Protocol. It provides file access, file
    management and file transfer over “a data stream”. With the Xceed
    Sftp component, that data stream is a SSH connection.

    SSH stands for Secure Shell. It is a
    network protocol for secure communication between two networked
    computers: a server and a client. Xceed Sftp implements the client
    side of SSH and SFtp.

    In order to use SFtp, a SSH connection
    must first be established. The SSH connection handles the network
    communication, setting up key exchange, encryption, data integrity
    and authentication and disconnecting. The Xceed.SSH.Client namespace
    implements the SSHClient class which exposes methods and properties
    for these actions.

    A SSHClient object is typically setup
    like this:

    (Begin
    C#)

    using
    Xceed.SSH.Client;

    /*
    … */

    SSHClient
    sshClient = new SSHClient();

    sshClient.Connect(
    “mysshserver.com”, 22 );

    sshClient.Authenticate(
    “username”, “password” );

    /*
    … */

    sshClient.Disconnect();

    (End
    C#)

    The example above uses password
    authentication. The component also supports public key
    authentication and keyboard-interactive authentication.

    Once the SSH connection has been
    successfully established, SFtp sessions can be started. The
    Xceed.SSH.Client namespace implements the SFtpSession class. This
    class represents a session between a client and an SFtp server. The
    SFtpSession class implements the IDisposable interface meaning that
    every SFtpSession object that is created should also be disposed of
    by calling the Dispose method or, in C#, creating the SFtpSession
    within a using block. If an instance of a SFtpSession object is not
    disposed of, its connection with the SFtp server may remain active
    until the SFtp server times-out or the garbage-collector clears the
    object.

    IMPORTANT BREAKING CHANGE NOTE: In the first release of the component, the class  Xceed.SSH.Client.SFtpSession was incorrectly called SFtpConnection. In all further builds and releases, the class name is SFtpSession. The SFtpConnection class still exists as a derived class of SFtpSession. But it has been marked as obsolete, Existing code can be modified to change the name SFtpConnection to SFtpSession. A simple “find and replace” in Visual Studio will do. The functionality remains the same.

    A SFtpSession object is typically setup
    like this:

    (Begin
    C#)

    using
    Xceed.FileSystem;

    /*
    … */

    using(
    SFtpSession sftpSession = new SFtpSession( sshClient ) )

    {

    AbstractFolder
    homeFolder = new SFtpFolder( sftpSession );

    }

    (End
    C#)

    The SFtpFolder class is a
    specialization of the AbstractFolder class that exposes properties
    and methods that provide access to a folder located on an SFtp
    server.

    The SFtpFile class is a specialization
    of the AbstractFile class that exposes properties and methods that
    provide access to a file located on an SFtp server.

    Technical overview and limitations

    This component implements version 2 of the SSH protocols (usually
    called SSH-2). Based on RFC 4250, RFC 4251, RFC 4252, RFC 4253, RFC
    4254 and draft-ietf-secsh-filexfer-13.

    SSH-1 support is not supported and is not planned.

    The component uses the following client version string:
    SSH-2.0-Xceed.SSH.<version number> where <version number>
    is the assembly’s major and minor version number. For example:
    SSH-2.0-Xceed.SSH.5.2

    The component implements the following algorithms. Not listing
    order indicated how they are requested in the key exchange
    initialization packet to the server.

    Key exchange:

    diffie-hellman-group1-sha1

    Public key:

    ssh-rsa

    Important note: supported key lengths for RSA range from 384 bits to 4096
    bits in increments of 8 bits if you have the Microsoft Enhanced
    Cryptographic Provider installed. Key lengths from 384 bits to 512
    bits are supported in increments of 8 bits if you only have the
    Microsoft Base Cryptographic Provider installed.

    Ssh-dss

    Important note: supported key lengths range for DSS (also known as DSA) from 512 bits to 1024
    bits in increments of 64 bits.

    Encryption (both directions):

    aes128-cbc

    aes256-cbc

    none

    Data integrity (both directions):

    hmac-sha1

    none

    Compression (both directions):

    none

    Languages (both directions):

    an
    empty list is always sent to the server

    Authentication

    password

    publickey

    Putty
    Private Key file (PPK)

    Support for more algorithms will be
    added in future versions of the component. This list will then be
    updated. It is currently not possible to change the order of the
    requested algorithms.

    The component implements portions of version 6 of the SFtp
    protocol. It also supports version 3. The component asks the server
    for version 6 but accepts version 3 if that version is included in
    the server’s reply. The component does not currently support any
    other version number (below 3 and version 4 and 5).

    The component has been tested with WinSSHD and OpenSSH server
    software.

    Usage

    The SFtpFolder and SFtpFile classes
    allow you to list folder contents, send files, receive files and get
    file and folder information.

    Items can be copied or moved (in other
    words, downloaded) from an SFtp server to a local drive, or any other
    type of folder supported by the Xceed FileSystem, using the CopyTo,
    CopyFilesTo, MoveTo, or MoveFilesTo methods.

    Items can be copied or moved (in other
    words, uploaded) from a local drive, or any other type of folder
    supported by the Xceed FileSystem to a SFtp server using the CopyTo,
    CopyFilesTo, MoveTo, or MoveFilesTo methods.

    So to download from a server, call the
    copy or move methods using a location on the server as the source and
    a local folder as the destination. For example:

    (Begin
    C#)

    AbstractFile
    sourceFile = new SFtpFile( sftpSession, “File1.dat” );

    AbstractFolder
    destinationFolder = new DiskFolder( “D:\\DownloadedFiles”
    );

    sourceFile.CopyTo(
    destinationFolder, true );

    (End
    C#)

    Conversely, to upload from a local
    drive to a location on a server, call the copy or move methods using
    a local file or folder as the source and a location on the server as
    the destination. For example:

    (Begin
    C#)

    AbstractFile
    sourceFile = new DiskFile( “D:\\SomeFile.dat” );

    AbstractFolder
    destinationFolder = new SFtpFolder( sftpSession );

    sourceFile.CopyTo(
    destinationFolder, true );

    (End
    C#)

    Naming conventions, home and root directories

    SFtp defines directory path separator
    as ‘/’. However, the Xceed FileSystem uses the ‘\’ character. When
    using SFtpFolder and SftpFile, always use ‘\’ as the folder
    separator. This allows consistency with the other specializations of
    FileSystemItem (DiskFile, ZippedFolder, etc).

    The component will translate the path separator internally.

    SFtp has concepts of the default directory, absolute and relative directories.

    File names starting with a backslash
    (‘\’) are “absolute”, and are relative to the root of the
    file system. That root is defined by the server and its value usually
    depends on the user that is authenticated.

    Names starting with any other character
    are relative to the user’s default directory. That default directory
    is defined by the server and its value usually depends on the user
    that is authenticated.

    An empty path name is valid, and refers
    to the default directory.

    A path name component “..”
    refers to the parent directory, and “.” refers to the
    current directory.

    These conventions are in effect when
    you specify paths for SFtpFile and SFtpFolder.

    For example, the lines

    AbstractFolder
    destinationFolder = new SFtpFolder( sftpSession );

    destinationFolder
    = new SFtpFolder( sftpSession, “” );

    both make ‘destinationFolder’ refer to
    the default directory. SFtpFolder internally resolves the logical
    default directory so that you can get the full, absolute path if you
    get the value of its FullName property. You will also get the folder
    name the default path refers to with the Name property.

    The line

    AbstractFile
    file = new SFtpFile( sftpSession, @“folder1\folder2\somefile.dat”
    );

    refers to a file, relative to the
    default directory. SFtpFile internally resolves the relative path so
    that you can get the full, absolute path if you get the value of its
    FullName property.

    Permissions

    The SFtp server decides what files and
    folders you see and files you have access to. Most of the time,
    access depends on the authenticated SSH user.

    One SSH connection, multiple SFtp sessions

    The SSH protocol has the ability to
    multiplex a single connection into several logical channels. SFtp is
    one such channel. That means that you can use the same SSHClient
    object to power multiple SFtpSession objects. For example, the
    following is allowed:

    SFtpSession
    sftpSession1 = new SFtpSession( sshClient );

    SFtpSession
    sftpSession2 = new SFtpSession( sshClient );

    /*
    … */

    sftpSession2.Dispose();

    sftpSession1.Dispose();

    Applies to Xceed SFTP for .NET. Imported from legacy forums. Posted by Jb [Xceed] (had 2860 views)

Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.