Simple-SFTP-Server - WeOnlyDo Software example code



All

wodCrypt (12)
wodSSH (10)
wodSFTP (23)
wodSSHServer (1)
wodSSHTunnel (11)
wodSSHpackage
wodSFTPdll

wodSSH.NET (10)
wodSFTP.NET (24)
wodFtpDLX.NET (22)
wodWebServer.NET (10)

wodAppUpdate (13)
wodHttpDLX (8)
wodFtpDLX (22)
wodTelnetDLX
wodFTPServer (3)
wodWebServer (10)
wodVPN
wodXMPP (13)
All ** [Visual Basic] ** [C#] ** [VB.NET] **

Simple SFTP Server
VB code
Public WithEvents FtpD As wodFTPDCom
Public key As Keys

Private Sub Form_Load()
    ' Initialize instance of wodFtpServer
    Set FtpD = New wodFTPDCom

    ' Initialize wodKeys object
    Set key = New Keys
End Sub

Private Sub Command1_Click()
    ' Generate the needed key pair
    key.Generate RSAkey
    Set FtpD.Certificate = key

    ' Let's specify SFTP protocol
    FtpD.Protocol = SFTP

    ' If not specified otherwise, wodFtpServer will listen on default protocol port (22 for SFTP)
    FtpD.Port = 22

    ' Start listening for connections.
    FtpD.Start
End Sub

Private Sub Command2_Click()
    ' Let's stop the server
    FtpD.Stop
End Sub

Private Sub FtpD_LoginPassword(ByVal User As wodFTPDComLib.FtpUser, ByVal Login As String, ByVal Password As String, ByRef Action As wodFTPDComLib.FtpActions)
    ' Accept all users, and assign default directory
    Action = Allow
    User.HomeDir = "c:\"
End Sub
VB.Net code
Public WithEvents FtpD As wodFTPDComLib.wodFTPDCom
Public key As wodKeys.Keys
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'Initialize instance of wodFtpServer
    FtpD = New wodFTPDComLib.wodFTPDCom

    ' Initialize wodKeys object
    key = New wodKeys.Keys
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    ' Generate the needed key pair
    key.Generate(wodKeys.SSHKeyTypes.RSAkey)
    FtpD.Certificate = key

    ' Let's specify SFTP protocol
    FtpD.Protocol = wodFTPDComLib.ProtocolsEnum.SFTP

    ' If not specified otherwise, wodFtpServer will listen on default protocol port (22 for SFTP)
    FtpD.Port = 22

    ' Start listening for connections.
    FtpD.Start()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    'Let's stop the server
    FtpD.Stop()
End Sub

Private Sub FtpD_LoginPassword(ByVal User As wodFTPDComLib.FtpUser, ByVal Login As String, ByVal Password As String, ByRef Action As wodFTPDComLib.FtpActions) Handles FtpD.LoginPassword
    'Accept all users, and assign default directory
    Action = wodFTPDComLib.FtpActions.Allow
    User.HomeDir = "c:\"
End Sub
C# code
private wodFTPDComLib.wodFTPDCom FtpD;
private wodKeys.Keys key;

private void button1_Click(object sender, EventArgs e)
{
    // Generate the needed key pair
    key.Generate(wodKeys.SSHKeyTypes.RSAkey, 1024);
    FtpD.Certificate = key;

    // Let's specify SFTP protocol
    FtpD.Protocol = wodFTPDComLib.ProtocolsEnum.SFTP;

    // If not specified otherwise, wodFtpServer will listen on default protocol port (22 for SFTP)
    FtpD.Port = 22; 

    // Start listening for connections.
    FtpD.Start(FtpD.Port);
}

void FtpD_LoginPassword(wodFTPDComLib.FtpUser User, string Login, string Password, ref wodFTPDComLib.FtpActions Action)
{
    // Accept all users, and assign default directory
    Action = wodFTPDComLib.FtpActions.Allow;
    User.HomeDir = "c:\\";
}

private void Form1_Load(object sender, EventArgs e)
{
    //Initialize instance of wodFtpServer
    FtpD = new wodFTPDComLib.wodFTPDCom();

    // Initialize the Keys object
    key = new wodKeys.Keys();

    FtpD.LoginPassword += new wodFTPDComLib._IwodFTPDComEvents_LoginPasswordEventHandler(FtpD_LoginPassword);
}

private void button2_Click(object sender, EventArgs e)
{
    //Let's stop the server
    FtpD.Stop();
}