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 SSH Server
VB code
Option Explicit Dim WithEvents wodSSHD1 As wodSSHDCom Private Sub Form_Load() Dim Filename As String Dim Password As String ' initialize wodSSHD Set wodSSHD1 = New wodSSHDCom ' first we need to load or generate key we will use ' in productional systems, generate both keys (RSA/DSA) ' here, just for the sample, one is enough. 'On Error Resume Next Filename = App.Path + "\mykey.rsa" ' we don't need to put password at all - but it's better in real life Password = "My secret password" ' try to load the key wodSSHD1.Keys.Load Filename, Password If Err <> 0 Then ' load failed - we will generate new one wodSSHD1.Keys.Generate RSAkey wodSSHD1.Keys.Save RSAkey, Filename, Password End If wodSSHD1.Protocol = SSH2 wodSSHD1.Port = 22 ' let's start listening wodSSHD1.Start End Sub Private Sub Form_Unload(Cancel As Integer) Set wodSSHD1 = Nothing End Sub Private Sub wodSSHD1_LoginPassword(ByVal User As wodSSHDComLIB.ISSHUser, ByVal Login As String, ByVal Password As String, Action As wodSSHDComLIB.SSHActions) ' allow everyone to come in and show that big message Action = Allow End Sub Private Sub wodSSHD1_ServiceRequest(ByVal User As wodSSHDComLIB.ISSHUser, ByVal ServiceIndex As Long, ServiceType As wodSSHDComLIB.SSHServiceTypes, ServicePath As String, Action As wodSSHDComLIB.SSHActions) ' ignore all requests for external subsystems, including portforwarding ServiceType = stNone End Sub Private Sub wodSSHD1_ServiceStart(ByVal User As wodSSHDComLIB.ISSHUser, ByVal ServiceIndex As Long, ByVal ServiceType As wodSSHDComLIB.SSHServiceTypes, ByVal ServiceName As String) ' show nice message User.Send "# # # ###### # #### #### # # ######" & vbCrLf User.Send "# # # # # # # # # ## ## #" & vbCrLf User.Send "# # # ##### # # # # # ## # #####" & vbCrLf User.Send "# # # # # # # # # # #" & vbCrLf User.Send "# # # # # # # # # # # #" & vbCrLf User.Send " ## ## ###### ###### #### #### # # ######" & vbCrLf User.Send vbCrLf & "You have connected to wodSSHD server. Feel free to stay." & vbCrLf & vbCrLf User.Send "You are coming from host " & User.RemoteIP & vbCrLf User.Send "Your login is " & User.Login & vbCrLf User.Send "You connected at " & Format(User.TimeConnected, "dddd, mmm d yyyy h:m") & vbCrLf User.Send "So far you have received " & User.BytesDownload & " bytes" User.Send vbCrLf & vbCrLf User.Disconnect ' we're done, disconnect user End Sub
VB.Net code
Option Explicit On Dim WithEvents wodSSHd1 As wodSSHDComLIB.wodSSHDCom Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim Filename As String Dim Password As String ' initialize wodSSHD wodSSHd1 = New wodSSHDComLIB.wodSSHDCom ' first we need to load or generate key we will use ' in productional systems, generate both keys (RSA/DSA) ' here, just for the sample, one is enough. On Error Resume Next Filename = Application.StartupPath + "\mykey.rsa" ' we don't need to put password at all - but it's better in real life Password = "My secret password" ' try to load the key wodSSHd1.Keys.Load(Filename, Password) If Err.Number <> 0 Then ' load failed - we will generate new one wodSSHd1.Keys.Generate(wodSSHDComLIB.SSHKeyTypes.RSAkey) wodSSHd1.Keys.Save(wodSSHDComLIB.SSHKeyTypes.RSAkey, Filename, Password) End If wodSSHd1.Protocol = wodSSHDComLIB.ProtocolsEnum.SSH2 wodSSHd1.Port = 22 ' let's start listening wodSSHd1.Start() End Sub Private Sub Form1_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed wodSSHd1 = Nothing End Sub Private Sub wodSSHd1_LoginPassword(ByVal User As wodSSHDComLIB.SSHUser, ByVal Login As String, ByVal Password As String, ByRef Action As wodSSHDComLIB.SSHActions) Handles wodSSHd1.LoginPassword ' allow everyone to come in and show that big message Action = wodSSHDComLIB.SSHActions.Allow End Sub Private Sub wodSSHd1_ServiceRequest(ByVal User As wodSSHDComLIB.SSHUser, ByVal ServiceIndex As Integer, ByRef ServiceType As wodSSHDComLIB.SSHServiceTypes, ByRef ServicePath As String, ByRef Action As wodSSHDComLIB.SSHActions) Handles wodSSHd1.ServiceRequest ' ignore all requests for external subsystems, including portforwarding ServiceType = wodSSHDComLIB.SSHServiceTypes.stNone End Sub Private Sub wodSSHd1_ServiceStart(ByVal User As wodSSHDComLIB.SSHUser, ByVal ServiceIndex As Integer, ByVal ServiceType As wodSSHDComLIB.SSHServiceTypes, ByVal ServiceName As String) Handles wodSSHd1.ServiceStart ' show nice message User.Send("# # # ###### # #### #### # # ######" & vbCrLf) User.Send("# # # # # # # # # ## ## #" & vbCrLf) User.Send("# # # ##### # # # # # ## # #####" & vbCrLf) User.Send("# # # # # # # # # # #" & vbCrLf) User.Send("# # # # # # # # # # # #" & vbCrLf) User.Send(" ## ## ###### ###### #### #### # # ######" & vbCrLf) User.Send(vbCrLf & "You have connected to wodSSHD server. Feel free to stay." & vbCrLf & vbCrLf) User.Send("You are coming from host " & User.RemoteIP & vbCrLf) User.Send("Your login is " & User.Login & vbCrLf) User.Send("You connected at " & String.Format("{0:dddd, MMM d yyyy HH:mm}", User.TimeConnected) & vbCrLf) User.Send("So far you have received " & User.BytesDownload & " bytes") User.Send(vbCrLf & vbCrLf) User.Disconnect() ' we're done, disconnect user End Sub C# code
private wodSSHDComLIB.wodSSHDCom wodSSHd1; private void Form1_Load(object sender, EventArgs e) { // initialize wodSSHD wodSSHd1 = new wodSSHDComLIB.wodSSHDCom(); wodSSHd1.LoginPassword += new wodSSHDComLIB._IwodSSHDComEvents_LoginPasswordEventHandler(wodSSHd1_LoginPassword); wodSSHd1.ServiceRequest += new wodSSHDComLIB._IwodSSHDComEvents_ServiceRequestEventHandler(wodSSHd1_ServiceRequest); wodSSHd1.ServiceStart += new wodSSHDComLIB._IwodSSHDComEvents_ServiceStartEventHandler(wodSSHd1_ServiceStart); String Filename = String.Empty; String Password = String.Empty; // first we need to load or generate key we will use // in productional systems, generate both keys (RSA/DSA) // here, just for the sample, one is enough. Filename = Application.StartupPath + @"\mykey.rsa"; // we don't need to put password at all - but it's better in real life Password = "My secret password"; // try to load the key try { wodSSHd1.Keys.Load(Filename, Password); } catch { wodSSHd1.Keys.Generate(wodSSHDComLIB.SSHKeyTypes.RSAkey, 1024); wodSSHd1.Keys.Save(wodSSHDComLIB.SSHKeyTypes.RSAkey, Filename, Password); } wodSSHd1.Protocol = wodSSHDComLIB.ProtocolsEnum.SSH2; wodSSHd1.Port = 22; // let's start listening wodSSHd1.Start(wodSSHd1.Port); } void wodSSHd1_LoginPassword(wodSSHDComLIB.SSHUser User, string Login, string Password, ref wodSSHDComLIB.SSHActions Action) { // allow everyone to come in and show that big message Action = wodSSHDComLIB.SSHActions.Allow; } void wodSSHd1_ServiceRequest(wodSSHDComLIB.SSHUser User, int ServiceIndex, ref wodSSHDComLIB.SSHServiceTypes ServiceType, ref string ServicePath, ref wodSSHDComLIB.SSHActions Action) { // ignore all requests for external subsystems, including portforwarding ServiceType = wodSSHDComLIB.SSHServiceTypes.stNone; } void wodSSHd1_ServiceStart(wodSSHDComLIB.SSHUser User, int ServiceIndex, wodSSHDComLIB.SSHServiceTypes ServiceType, string ServiceName) { // show nice message User.Send("# # # ###### # #### #### # # ######" + "\r\n", ServiceIndex); User.Send("# # # # # # # # # ## ## #" + "\r\n", ServiceIndex); User.Send("# # # ##### # # # # # ## # #####" + "\r\n", ServiceIndex); User.Send("# # # # # # # # # # #" + "\r\n", ServiceIndex); User.Send("# # # # # # # # # # # #" + "\r\n", ServiceIndex); User.Send(" ## ## ###### ###### #### #### # # ######" + "\r\n", ServiceIndex); User.Send("\r\n" + "You have connected to wodSSHD server. Feel free to stay." + "\r\n" + "\r\n", ServiceIndex); ; User.Send("You are coming from host " + User.RemoteIP + "\r\n", ServiceIndex); User.Send("Your login is " + User.Login + "\r\n", ServiceIndex); User.Send("You connected at " + String.Format("{0:dddd, MMM d yyyy HH:mm}", User.TimeConnected) + "\r\n", ServiceIndex); User.Send("So far you have received " + User.BytesDownload + " bytes", ServiceIndex); User.Send("\r\n" + "\r\n", ServiceIndex); User.Disconnect(); // we're done, disconnect user } |