Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSH cmd sending and receiving #3

Closed
Clio75 opened this issue Mar 26, 2020 · 9 comments
Closed

SSH cmd sending and receiving #3

Clio75 opened this issue Mar 26, 2020 · 9 comments
Assignees
Labels
question Further information is requested

Comments

@Clio75
Copy link

Clio75 commented Mar 26, 2020

Hi,

I'm trying to use this toolkit to send and received cmd over ssh. I'm find the Execute that sending CMD. but how to received the answer ?

Great toolkit :D Looking forward to test it more

@volks73 volks73 added the question Further information is requested label Mar 26, 2020
@volks73
Copy link
Member

volks73 commented Mar 26, 2020

Since libssh2-labview is a wrapper around the libssh2 C library, but with a C "adapter" library to make the libssh2 library more LabVIEW-friendly, the examples for the libssh2 library can be helpful. There is the ssh2_echo.c and ssh2_exec.c examples that can act as a guide for reading the response from a command over SSH. However, I recognize the examples are a little low-level, and written in C, which is sometimes difficult to reason about and/or maybe unfamiliar.

Unfortunately, I do not currently have an example in LabVIEW for each of the libssh2 C library examples, which would be the most helpful. The current examples focus on SFTP, which was the main functionality needed by another collaborate at the initiation of this project. I will create a feature request/issue to add more examples.

There is the Channel.lvlcass:Read All.vi from the Channel "class". This is probably the VI you want to use after executing the command. It encapsulates a lot of the reading functionality that appears in the C echo and execute examples. Here is a totally untested VI snippet that might work:

Example Execute Read

@volks73
Copy link
Member

volks73 commented Mar 26, 2020

I have created #4 to track creation of examples.

Please let me know if the above VI snippet works and would be a good example.

@Clio75
Copy link
Author

Clio75 commented Mar 26, 2020

I will test and give you feedback shortly :)

@Clio75
Copy link
Author

Clio75 commented Mar 26, 2020

Hi,

I have one problem
image

Red square : Do I have correct destroy channel ?
I can't find the same symbol as you have in your snippet.

Blue square : Is this correct ?

Let me know what I'm doing wrong :)

@volks73
Copy link
Member

volks73 commented Mar 26, 2020

The Close.vi should be Destroy.vi. In the toolkit, for every Create there is a Destroy and for every Open (sometimes buried within a Create or Initialize VI) there is a Close VI. The wrong VI appeared to be used in this palette. Please see the attached ZIP/VIP with the updated palette that contains the missing Destroy.vi.

However, my example should be amended to include using the Close.vi in addition to the Destroy.vi. Here is an updated VI snippet, still untested, and might work:

Channel Exec-Read Example v2

field_rnd_services_libssh2-1.0.0.9.zip

@Clio75
Copy link
Author

Clio75 commented Mar 26, 2020

Perfect 💃 🥇
Everything is working.
And yes this is a good example to distribute with toolkit/package :)

@Clio75
Copy link
Author

Clio75 commented Mar 26, 2020

Just a comment:
Can the close channel be inside the destroy channel. I believe that is more intuitive for the user
Like you also sad, Create -> destroy. Open-> Close.

@volks73
Copy link
Member

volks73 commented Mar 26, 2020

Can the close channel be inside the destroy channel. I believe that is more intuitive for the user
Like you also sad, Create -> destroy. Open-> Close.

I agree, and I have a vague reconcolation not really like this inconsistency within the API for the channels, but there appears to be some occasions where the channel does not always need to be closed, but it does always need to be destroyed, a.k.a. freed. Looking at the examples for the libssh2 library, only the ssh2.c, ssh2_agent.c, ssh2_echo, and ssh2_exec.c examples explicitly use the libssh2_channel_close function (Close.vi), but all examples use the libssh2_channel_free function (Destroy.vi).

All of the examples use a variant of the libssh2_channel_open_ex function to create the channel, so the Create.vi is actually polymorphic and the type of open function is determined by the instance of the Create.vi selected. The default instance is to use the libssh2_channel_open_session function. I remember combining the creation of the channel with the opening of a channel as a convenience and to decrease the number of VIs needed to "get going", and opening was always required.

A possible complication, if you look at the VI snippet in the README for uploading a file to a remote SSH server, there is the Close Channel and Wait on Close Channel VIs. So, how would including the Close VI in with the Destroy VI work if the user of the toolkit wanted to wait for the close signal to be received before destroying the channel?

Basically, the inconsistency is a result of the libssh2 implementation and trying to create an ergonomic wrapper between C and LabVIEW. There is an Open and Close functions within the libssh2 library, but the Open is "morphed" into the Create functionality for the adapter library and the LabVIEW toolkit.

I think technically the Close is not actually needed, but good practice. I also think that always executing a Close when the channel is destroyed may not hurt as well.

This is all probably way more information than you want or need, but I am going to create a separate issue to track resolution of this inconsistency, which does annoy me, too.

@volks73
Copy link
Member

volks73 commented Mar 26, 2020

See Issue #6 for tracking the inconsistent naming. I believe this issue has been resolved.

@volks73 volks73 closed this as completed Mar 26, 2020
@volks73 volks73 changed the title SSH cmd sending and reciving SSH cmd sending and receiving Jan 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants