+1 vote
by (160 points)
edited by

I want to create an SFTP Server that does not work the the file system, but rather accesses my API and returns content from the API as files. I have authentication working, however, I am having a hard time figuring out how to get the ShellCommand event working with ShellType.Empty. The help on this is very poor. A Google search only returns one result.

From what I can tell, if add a user like this:

FileServerUser(Username, Password, ShellType.Empty);

Then I must handle the ShellCommand event like this:

_server.ShellCommand += _server_ShellCommand;
void _server_ShellCommand(object sender, ShellCommandEventArgs e)
{
}

According to the help, I can use e.Command and e.Args to determine the command that was sent from the client. I have the ability to use the e.Write, e.WriteLine and e.ExitCode methods to send a response to the client.

What I need is a list of standard shell command responses for each of the FTP commands rather than having to figure this out from scratch.

What I would have liked:
* The ability to specify a path and ShellType.Default when creating the user and override the behavior of any command of my choosing, or alternatively, let the default shell command handler handle a command that I have not overriden.

Another problem: When I connect with FileZilla using ShellType.Empty, the first ShellCommand event that fires is a "test" command with 5 parameters. This does not appear to be a standard FTP command and I'm not sure exactly what I should return.

Complaint: The code obfuscation is not helpful. I would much rather have just perused the source code to figure out what to do, but one can only go so far with the obfuscation. Is there an option to buy with source?

Applies to: Rebex SFTP
by (58.9k points)
One more question to clarify. Are you looking for a virtual file system API that would present the SFTP server file system, but it would take the "virtual files" from your API's? The FileServer does not support it yet, but we are already working on it, so we can share a beta when ready.
by (160 points)
Yes, that is exactly what I am looking for :). Do you perhaps have an ETA for the beta?
by (58.9k points)
Well, we do not have a fixed ETA for this, but we will post here as soon as we have a beta version of the upcomming virtual FileSystem API.
by (132k points)
Sorry for the delay - we changed our beta testing approach for this in the meantime. Virtual file system API has been released with Rebex File Server 2017 R4: https://www.rebex.net/file-server/features/virtual-filesystems.aspx

1 Answer

0 votes
by (58.9k points)
selected by
 
Best answer

At the moment the default built-in shell commands
that we support are only the SCP commands*, and you have to set a virtual root for the user, otherwise it will not work.
Please try this code to create a SFTP server that by default implements SCP shell commands and let me know whether it helps:

// create a server instance
var server = new FileServer();

// bind virtual shell with SCP support (runs over SSH) to port 22
server.Bind(22, FileServerProtocol.Shell);

// load a server private key from encrypted 'serverkey.ppk' file
server.Keys.Add(new SshPrivateKey("server-key.ppk", "password"));

// add a user (specify username, password and virtual root path)
server.Users.Add("user01", "password", @"c:\data\user01");

// start the server in the background
server.Start();

With the code above you can still implement the FileServer.ShellCommand event handler and implement a new command or override the behaviour of an existing one.
As to the source code version it is available, but not directly from the webpage. If you are interested in purchasing it, please send us an email to support@rebex.net.

*As of Rebex File Server 2016 R2.2, the list of SCP supported commands is:
whoami, uname, hostname, echo, mv, rm, pwd, mkdir, rmdir, dir, cp, ls, groups, cd, set, exit, help)

by (160 points)
Thank you - this looks like it might do the trick.
...