Discuss this help topic in SecureBlackbox Forum

SFTP: Connect TElSFTPServer with SSH server classes

SFTP is a protocol that runs over specialized "sftp" subsystem of SSH protocol. To allow SFTP in the SSH server, you need to add "sftp" to the list of allowed subsystems using TElSSHServer.AllowedSubsystems.Add() method:

C#:


TElSSHServer server = new TElSSHServer();
...
server.AllowedSubsystems.Add("sftp");

Next you need to handle TElSSHServer.OnOpenSubsystem event. In its event handler you check if the requested subsystem is named "sftp", and, if it is, you can proceed with starting an SFTP session.

OnOpenSubsystem event has Connection parameter, which passes the object of TElSSHTunnelConnection type. You need to instantiate two more objects - TElSFTPSSHSubsystemHandler and TElSSHSubsystemThread. TElSFTPSSHSubsystemHandler needs the passed TElSSHTunnelConnection, and TElSSHSubsystemThread is instantiated with the instance of TElSFTPSSHSubsystemHandler as a parameter.

TElSFTPSSHSubsystemHandler class has Server property, which references an instance of the pre-created TElSFTPServer object. All you need to do is configure this TElSFTPServer object and resume an instance of TElSSHSubsystemThread.

C#:


private void SSHServer_OnOpenSubsystem(object Sender, TElSSHTunnelConnection Connection, string Subsystem)
{
	if (Subsystem == "sftp")
	{
		SFTPSession sess = new SFTPSession(Connection);
	}
}
...
public SFTPSession(TElSSHTunnelConnection conn)
{
	m_thread = new TElSSHSubsystemThread(new TElSFTPSSHSubsystemHandler(conn, true), conn, true);
	TElSFTPSSHSubsystemHandler handler = (TElSFTPSSHSubsystemHandler)m_thread.Handler;
	handler.Server.OnClose += new SBUtils.TNotifyEvent(Server_OnClose);
	...
	m_thread.Resume();
}

How To articles about SFTP server

Discuss this help topic in SecureBlackbox Forum