0

I'm in the process of trying to copy an hdf5 binary file on a local machine to a remote computing blade. I am using libssh to copy the desired directory or files out after they are generated by my Qt application. Using libssh I am able to open an ssh_session, authenticate it, open a channel and send remote commands.

for (QStringList::iterator it = ipList.begin(); it != ipList.end(); ++it)
{
    ssh_session my_session = new ssh_new();
    QString ip_address = *it;
    ssh_options_set(my_session, SSH_OPTIONS_HOST, ip_address.toStdString().c_str());

    // Connect...Authenticate using public key....

    QString command = QString("rm -r %2; cp -r %1 %1; cp /local/file.txt /remote/file.txt").arg(local_dir, remote_dir);
    execute_remote_command(my_session, command.toStdString().c_str());
        // Open channel and execute command

    ssh_disconnect(my_session);
    ssh_free(my_session);
}

This command is being executed for each individual computing blade. In between each of the calls I am closing and opening an ssh session to the next blade. The files make it out the blades but they appear to be corrupt. They are the exact same file size. I haven't figured out a way to compare the individual bytes to see just how corrupt they are, any tips there would be appreciated as well.

When I run my ssh copy commands in a separate test terminal program the files appear to make it intact and are readable on the blades. The issue only seems to occur when the files are moved from within the Qt GUI program.

EDIT: So delving a little bit deeper into what is wrong, it appears that the file on the remote server is not the same size. It appears to be missing a large portion of the bytes. On top of that when I examine what is there byte by byte with the local version of the file, almost all of the bytes differ.

Wired365
  • 199
  • 1
  • 13
  • 3
    So I know I am still new here but could someone please tell me what is wrong about this question that is causing it to get down voted so quickly or ways to improve it? There are next to no examples for libssh and I've searched for weeks for an answer to this and come up with nothing. – Wired365 May 27 '16 at 13:42
  • 3
    In your question's current form, there's really no way to provide a meaningful answer. Please edit your question to include the relevant source code from your program. And try to identify what is wrong with the transferred files--are they too short? Too long? Are the bytes wrong? Also, there's a lot of unnecessary verbiage in your question. Try to trim it down to what is relevant to your problem. – Kenster May 27 '16 at 14:50
  • Thanks for the tip, I'll clean it up. – Wired365 May 27 '16 at 15:08
  • You show no code, no minimal example, and libssh "examples" are really the programs that use it. Go on any linux/unix system and use the package manager to find out what packages depend on that library, then look in their sources. – Kuba hasn't forgotten Monica May 27 '16 at 15:10
  • @KubaOber Thanks for the tip. When it comes to the code I am running it's hard to pick and choose what to place without it being a wall of text. I am using the examples on the libssh website almost verbatim to set up the connection, the only difference is the command that I am passing. – Wired365 May 27 '16 at 15:24
  • Thanks again for the tips. I'll try to be a lot clearer with my questions in the future. – Wired365 May 27 '16 at 18:58

1 Answers1

0

Turns out the answer was that the HDF5 writer wasn't being closed properly before the SSH commands were being called. I fixed the problem by dynamically allocating the custom H5 class that someone else wrote and made sure to delete it before the SSH commands were called. Turns out whoever wrote the HDF5 read and write class didn't handle file opening and closing properly and didn't provide functions to do so.

Below is an example of what I am talking about.

HDF5writer_class *hdf5_writer = new HDF5writer_class();
hdf5_writer->create_file("/local/machine/hdf5_file.h5");

// ... add the data to the file

delete hdf5_writer;

// Open SSH Session and run the copy commands

Long story short, make sure the file you are writing is closed and released for use before you try to copy it.

Wired365
  • 199
  • 1
  • 13