EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Best Practice to Handle SFTP Server Events

Also by EldoS: CallbackDisk
Create virtual disks backed by memory or custom location, expose disk images as disks and more.
#19561
Posted: 03/22/2012 11:51:50
by Taylor Eagy (Standard support level)
Joined: 03/22/2012
Posts: 2

There are two SFTP server events that I'm trying to allow my class to handle: OnWriteFile and OnClose. Since SFTP is build upon SSH and my application class is using a listener that manages the SSH sessions (Application -> Listener -> SSHSession -> SFTPSession), what would be the proper way to trigger the events from SFTP up to my application class to handle?

An easy way I can think of is to create the handlers like this in the application class:

Code
public static void Server_OnWriteFile(object Sender, object Data, long Offset, byte[] Buffer, int BufferOffset, int Count, ref int ErrorCode, ref string Comment)
{
   //do stuff
}

public static void Server_OnClose(object Sender)
{
   //do stuff
}


And then register the handlers in the SFTPSession constructor like:
Code
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(MyApplicationClass.Server_OnClose);
}


Or would it be better practice to send the event up the chain of classes (SFTPSession -> SSHSession -> Listener -> MyApplicationClass) similar to how the SSHServer demo handles the OnSessionChange event?
#19562
Posted: 03/22/2012 13:54:54
by Mykola Olshevsky (Basic support level)
Joined: 07/07/2005
Posts: 450

It depends on you application design, but IMO the best way is to handle them on class dedicated for SFTP server events handling (like SFTPSession), and, depending on your needs call there methods from class which represents file system. Main application's class should only handle staff for server starting/stopping/access to configuration.
#19563
Posted: 03/22/2012 14:04:18
by Taylor Eagy (Standard support level)
Joined: 03/22/2012
Posts: 2

Ok, thanks for the response.

Reply

Statistics

Topic viewed 952 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!