fieldrndservices / libssh2-labview

A LabVIEW library for SSH client support via libssh2
Apache License 2.0
21 stars 2 forks source link

Error -8146 at "Create from SCP Send.vi" (DLL returned status -31 "SCP Protocol Error") #51

Closed jimkring closed 2 years ago

jimkring commented 2 years ago

Hi Chris,

I got this error when trying to transfer files to a PXI system running NI Linux RT.

Error -8146 at "Create from SCP Send.vi"

I dug a little deeper and see that the call to the lv_libssh2_scp_send function in libssh2lv.dll is returning a status value of -31 ("SCP Protocol Error")

Can you think of any reasons this might be happening or good next steps for debugging?

Note: I have two PXI's and they are on different networks. Maybe the PXI's have a slightly different software configuration or there's a difference in the network.

Thanks for your help. Loving the libssh2-labview toolkit!

Jim

volks73 commented 2 years ago

It is possible the SCP Protocol Error is not correct. I have to check the C implementation to see if it is related to https://github.com/fieldrndservices/libssh2-labview/issues/36#issuecomment-926916581, which was about the scp_recv2 but might still be relevant. While that issue and related comment is about SCP receiving, it still seems there is a lot of overlap with the SCP send.

The libssh2.org HTML documentation for the libssh2_scp_send_ex function, which the low-level C function that runs the SCP Send command has no content for the LIBSSH2_ERROR_SCP_PROTOCOL error. I stand my point in the linked comment that the SCP protocol does not change very often. It does appear that the C function in the libssh2lv library is correctly reporting the type of error, but I did not do a very deep investigation or test.

Can you think of any reasons this might be happening or good next steps for debugging?

Can you run the SCP command from a terminal/PuTTY with -vvv to print logging statements to the terminal? It is not possible to do this in the this toolkit unfortunately, but seeing the log messages from the CLI/terminal might provide more information on the PXI's SSH server configuration. Similarly, you can enable debugging on the SSH server for the PXI system and watch/read the logs to see why SCP might not be working. The error is not very helpful, but maybe the server will be.

There is a general trend to move away from SCP and use SFTP. Do any of the SFTP commands work for sending/receiving files to the remote PXI system?

Note: I have two PXI's and they are on different networks. Maybe the PXI's have a slightly different software configuration or there's a difference in the network.

This is very possible. Are they identical PXIs, firmware, and Linux RT OS images? Can you check the version of SSH server on each PXI system? Maybe they are different versions and the difference is causing the problem.

jimkring commented 2 years ago

Thanks for the thoughtful response. 

TLDR; The problem was that the upload folder did not exist on the target (where I was trying to upload the file into).

Details:

I was able to resolve the issue by switching from the SCP VIs to the SFTP VIs. This resulted in a more descriptive error message stating ~"the file does not exist" (paraphrasing), even though I was uploading with the Create file option of the SFTP Upload VI enabled. I then remembered to check to see if the FOLDER where I'm trying to upload the file actually exists and it didn't -- doh!!!, that was the problem. I resolved it by sending (over SSH) an mkdir -p /parent/folder/location/ command to ensure the folder exists. (Side note: the -p or --parents option is nice because it will create all needed folders, recursively, and doesn't return an error if the folder already exists).

OK, that's the story of my adventure in tracking down this error. The good news is I learned a few new things :)

Thanks again for your help and I hope my reporting of this problem (of my own making) is helpful to others.

One last thought: Maybe adding an mkdir -p $UPLOAD_FOLDER SSH command to the SFTP and SCP example VIs would help users avoid possible errors. This could be encapsulated into a VI that looks like the shipping (with LabVIEW) VI that does the same or the OpenG VI "Create Folder if Non-Existent.vi".  Just a thought...

Regards,

volks73 commented 2 years ago

I am glad you were able to resolve the issue. The error message was not much help but it looks like SFTP was a little more helpful.

One last thought: Maybe adding an mkdir -p $UPLOAD_FOLDER SSH command to the SFTP and SCP example VIs would help users avoid possible errors. This could be encapsulated into a VI that looks like the shipping (with LabVIEW) VI that does the same or the OpenG VI "Create Folder if Non-Existent.vi". Just a thought...

I have created #52 to consider implementing the idea of a mkdir -p like VI and/or example.