0 votes
by (8.4k points)
edited

I created a program which uses Rebex SFTP component and it works fine. Does Rebex SFTP also work to a FTP site? Do I need some code changes for switching from SFTP to FTP site?

Applies to: Rebex FTP/SSL, Rebex SFTP

1 Answer

0 votes
by (58.9k points)
edited
 
Best answer

Hello,

FTP and SFTP are two different file transfer protocols. Rebex provides two different components, represented by Ftp and Sftp classes.

There is also IFtp interface which encapsulates methods, properties and events, which are defined in Ftp class as well as in Sftp class.

If your application needs connecting to both FTP and SFTP servers, the IFtp interface allows you to write most of the code just once (for both protocols).

The iFTP interface can be used like this:

        // declare a protocol-independent variable
        IFtp client;

        // connect to the server according to its type
        switch (serverType)
        {
            case "ftp":  
                // create instance of Ftp object        
                var ftp = new Ftp();        
                // connect and authenticate to an FTP server using FTP/SSL Explicit       
                ftp.Connect(hostname, SslMode.Explicit);        
                ftp.Login(username, password);       
                // assign the Ftp instance to an IFtp variable     
                client = ftp;     
                break;   
            case "sftp":      
                // create instance of Sftp object  
                var sftp = new Sftp();     
                // connect and authenticate to an SFTP server   
                sftp.Connect(hostname);      
                sftp.Login(username, password);  
                // assign the Sftp instance to an IFtp variable     
                client = sftp;     
            break;   
            default:        
                throw new InvalidOperationException();
        }

        // the remaining code works with both FTP and SFTP connection
        client.ChangeDirectory(targetDirectory);
        client.PutFile(@"c:\data\file.txt", "file.txt");
        // even disconnecting can be done using IFtp
        client.Disconnect();

For more information about SFTP and FTP difference see http://www.rebex.net/kb/secure-ftp/default.aspx

If you have already purchased the SFTP component or FTP component you can upgrade to Rebex File Transfer Pack (it contains both SFTP and FTP components). Upgrading within 90 days after original purchase costs the price difference only.

...