Dart Home | PowerTCP SFTP & SSH for .NET | Custom Development | Reply | PowerTCP SFTP & SSH for .NET Topics | Forums |
Author | Forum: PowerTCP SFTP & SSH for .NET Topic: I want to connect to linux server via SSH using powertcp SSH and SFTP for .NET |
michaelteoh From: Malaysia Posts: 5 Member Since: 01/01/18 |
posted February 13, 2018 2:42 AM Hi all experts, Recently I just bought a copy of PowerTCP SSH and SFTP for .NET from Dart.com. I have gone through the sample coding and I still got not idea how can I connect to linux Server via SSH using the above mentioned tool. The most important thing is to connect to the server without interface (background processes). Can anyone (expert out there) have experience on this? Thanks for advise. By the way, I am using vb.net 2016 |
Jamie Powell (Admin) From: Rome, NY USA Posts: 448 Member Since: 03/13/07 Extra Support Options Custom Application Development |
posted February 13, 2018 3:39 PM Thank you for your post. An email has been sent to you requesting additional product information. Regards, Jamie |
Nick B (Admin) From: Utica, NY USA Posts: 619 Member Since: 05/25/10 Extra Support Options Custom Application Development |
posted February 15, 2018 1:20 PM Here's a snippet that demonstrates logging into a Linux SSH server, executing an 'ls' command, reading the response (assuming the command-line prompt is '$'), and disconnecting, in VB.NET: 'Connect to the server and authenticate with username/password (other options are available as well) ssh1.Connection.RemoteEndPoint.HostNameOrAddress = myServerHostname ssh1.Connection.RemoteEndPoint.Port = myServerPort 'Usually 22 ssh1.Connect() Dim loginDetails As New SshLoginData() loginDetails.Username = username loginDetails.Password = password ssh1.Authenticate(loginDetails) Dim sessionStream1 As SessionStream = ssh1.StartShell()) 'Send a list command sessionStream1.Write("ls -la" & vbCr) 'Read until the expected command prompt is received Dim response As String = sessionStream1.Read("$", Nothing).ToString() sessionStream1.Close() ssh1.Close() 'Utilize 'response' as desired In C# for others: //Connect to the server and authenticate with username/password (other options are available as well) ssh1.Connection.RemoteEndPoint.HostNameOrAddress = myServerHostname; ssh1.Connection.RemoteEndPoint.Port = myServerPort; //Usually 22 ssh1.Connect(); SshLoginData loginDetails = new SshLoginData(); loginDetails.Username = username; loginDetails.Password = password; ssh1.Authenticate(loginDetails); SessionStream sessionStream1 = ssh1.StartShell()); //Send a list command sessionStream1.Write("ls -la\r"); //Read until the expected command prompt is received string response = sessionStream1.Read("$", null).ToString(); sessionStream1.Close(); ssh1.Close(); //Utilize 'response' as desired |
michaelteoh From: Malaysia Posts: 5 Member Since: 01/01/18 |
posted March 4, 2018 9:26 PM what if the Dim response As String = sessionStream1.Read("$", Nothing).ToString() not returning the expected string? will the waiting stop? what should I do? the system hang |
Nick B (Admin) From: Utica, NY USA Posts: 619 Member Since: 05/25/10 Extra Support Options Custom Application Development |
posted March 5, 2018 11:14 AM Hello, Per the documentation here: http://www.dart.com/help/ptsshnet/webframe.html#Dart.Ssh~Dart.Ssh.SessionStream~Read(String,Object).html This method blocks until the delimiter is found, the timeout period expires, or the server closes the connection. If the method times out, all received data will be returned, and an exception will NOT be thrown. Instead, the returned Data.Delimiter will be null, indicating the delimiter was not found. Can you clarify 'the system hang'? In a single-threaded application, the application will be "blocked" so it will appear to hang, but stop after the timeout period expires. However, your entire system should not hang. |
michaelteoh From: Malaysia Posts: 5 Member Since: 01/01/18 |
posted March 5, 2018 7:30 PM can I customize the timeout limit? |
Nick B (Admin) From: Utica, NY USA Posts: 619 Member Since: 05/25/10 Extra Support Options Custom Application Development |
posted March 6, 2018 11:52 AM Hello, Yes, it is configured with SessionStream.ReadTimeout. |
michaelteoh From: Malaysia Posts: 5 Member Since: 01/01/18 |
posted March 7, 2018 2:04 AM OK, thanks. What if I want to grab everything from the sessionStream1.Read without putting any delimiter string to search... how will be the script looks like? ? |
Nick B (Admin) From: Utica, NY USA Posts: 619 Member Since: 05/25/10 Extra Support Options Custom Application Development |
posted March 7, 2018 11:21 AM Hello, A read loop is demonstrated within the snippet here: http://www.dart.com/help/ptsshnet/webframe.html#Dart.Ssh~Dart.Ssh.SessionStream~Read(Byte[]).html Or you could use ReadToEnd() if you want to just consume all data until the connection is closed: http://www.dart.com/help/ptsshnet/webframe.html#Dart.Ssh~Dart.Ssh.SessionStream~ReadToEnd.html |
Reply | PowerTCP SFTP & SSH for .NET Topics | Forums |
This site is powered by PowerTCP WebServer for ActiveX |