Common interface/usage for FTP and SFTP

+1 vote
asked Jul 12, 2010 by Akshay (130 points)
edited Jan 28, 2013

Is there a version of the library that has a common interface for Ftp and for Sftp. I need to toggle between the two in a library however because I don't see a common interface, I essentially have to duplicate all the code, with exactly the same calls.

Applies to: Rebex FTP/SSL, Rebex SFTP

3 Answers

+1 vote
answered Jul 13, 2010 by Lukas Matyska (52,850 points)
edited Jul 13, 2010

We are planning to release a Remote File System which is exactly what you want. It wasn’t officially released yet, but you can download a preview from http://www.rebex.net/extras/RFS.ConsoleSample.zip

commented Jul 28, 2010 by Akshay (130 points)
Thanks, I will take a look.
commented Jul 28, 2010 by Akshay (130 points)
We browsed through the new common RemoteFileSystem which is shared with Ftp and SFtp, however we noticed that the calls differ from what is currently on both of those. At the moment to get around the problem, since both use the same method calls, we're using C#'s dynamic variables and in the new RemoteFileSystem, we'd have to change all of our method calls. Since all the calls are shared, could the API remain the same?
commented Jul 29, 2010 by Lukas Pokorny (100,710 points)
Which calls do you mean? Could you post their names? Some methods are missing from RemoteFileSystem and some are different, but some of this can't be changed - for example, Rebex FTP's GetList returns an instance of FtpList while SFTP's GetList returns SftpItemCollection - these classes are very similar but not identical. Therefore the common API's GetList must return something else (although it will probably be a common ancestor of both FtpList and SftpItemCollection. The same applies to some other methods, properties and events.
commented Jul 29, 2010 by Lukas Pokorny (100,710 points)
To sum it up: please do let us know what exactly which calls were missing, different or otherwise problematic. The common API is a work in progress and we might be able to do something about this issue. Thanks!
0 votes
answered Oct 4, 2011 by cdbivfs74 (140 points)
edited Oct 10, 2011

I notice that the original question was answered over a year ago. Do you now have the Remote File System completed, or if not will you soon? We need to switch back and forth between ftp and sftp as well.

commented Oct 5, 2011 by Lukas Matyska (52,850 points)
edited Oct 10, 2011

The common interface for FTP and SFTP is already implemented. It will be available within the next public release. You will be able to use new IFtp interface for common functions as follows:

// declare common interface
IFtp client;

// the protocol to use
if (UseFtp)
{
    Ftp ftp = new Ftp();
    ftp.Connect(...);
    ftp.Login(...);
    client = ftp;
}
else
{
    Sftp sftp = new Sftp();
    sftp.Connect(...);
    sftp.Login(...);
    client = sftp;
}

// do some work
client.ChangeDirectory(...);
client.GetFile(...);

If you want to get the trial beta version, please let us know.

commented Oct 5, 2011 by cdbivfs74 (140 points)
edited Oct 5, 2011

When you get a directory listing will there be a common object for both ftp and sftp for the list collection and its items?

commented Oct 5, 2011 by Lukas Matyska (52,850 points)
edited Oct 5, 2011

Yes, there will be the DirectoryItemCollection class which is ancestor of FtpCollection and SftpCollection. It will contain the DirectoryItem objects (ancestor of FtpItem and SftpItem). The code can look like this:

IFtp client = ...;
DirectoryItemCollection list = client.GetList();
foreach (DirectoryItem item in list)
{
    Console.WriteLine("{0} {1} ...", item.Name, item.Length, item...);
}

Please note, the DirectoryItemCollection and the DirectoryItem are not final names. They will be probably renamed.

commented Oct 5, 2011 by cdbivfs74 (140 points)
edited Oct 5, 2011

Sounds good, we're looking to implement something ASAP, so when is your public release of this scheduled?

commented Oct 5, 2011 by Lukas Matyska (52,850 points)
edited Oct 5, 2011

The next public release is scheduled for November 2011. I can send you beta version if you want to try the common API.

commented Oct 8, 2011 by asherber (330 points)
edited Oct 8, 2011

I've got the current trial version from the website, but I'd love to get the beta with the common interface, since this is exactly what I need to do as well.

0 votes
answered Jan 28, 2013 by pkeil (200 points)
edited Jan 28, 2013

Ok, ignore this, I was using the old binaries.

Good work! Thanks a lot.

commented Jan 28, 2013 by Jan Sotola (16,920 points)
edited Jan 28, 2013

The IFtp interface was released in version release 2012R1. You can also find it in our on-line help.

The interface is a part of Rebex.Networking.dll so it is available in most of Rebex components, especially in Rebex FTP/SSL, Rebex SFTP, Rebex File Transfer Pack or Rebex Total Pack.

commented Jan 28, 2013 by Jan Sotola (16,920 points)
edited Jan 28, 2013

For now, we've not promoted the interface too much. You can look on a small example of initializing IFtp instaces.

We are planning to complete the common FTP / SFTP usage with providing a new FileTransfeClient class. It will implement the IFtp interface and it will also maintain a uniform creating of FTP or SFTP connections. Together with this new class we will publish appropriate set of samples and tutorials.

...