Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Rsync, sshpass and QProcess
Forum Updated to NodeBB v4.3 + New Features

Rsync, sshpass and QProcess

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 805 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TomNow99
    wrote on 1 May 2022, 11:38 last edited by
    #1

    Hi,

    I would like to use Rsync in QT. When I run this line in command line, it works:

    rsync -vr --rsh="/usr/bin/sshpass -p 'password' ssh -o StrictHostKeyChecking=no -p 22 -l user" 192.168.10.10:/abc/ /def/
    

    So in Qt I do the same:

    process->start("rsync -vr --rsh=\"/usr/bin/sshpass -p 'password' ssh -o StrictHostKeyChecking=no -p 22 -l user\" 192.168.10.10:/abc/ /def/", args);
    // args is empty QStringList()
    

    And this doesn't work.

    I find simillar topic:
    https://forum.qt.io/topic/127028/unable-to-run-qprocess-with-sshpass-in-windows

    So I try:

    process->start("rsync", QStringList()<<"-vr"<<"--rsh=\"/usr/bin/sshpass -p 'password' ssh -o StrictHostKeyChecking=no -p 22 -l user\""<<"192.168.10.10:/abc/"<<"/def/");
    

    ( I get output: Rsync: Failed to exec /usr/bin/sshpass -p 'password' ssh -o StrictHostKeyChecking=no -p 22 -l user No such file or directory

    And I try something like:

    process->start("rsync", QStringList()<<"-vr"<<"--rsh=\"/usr/bin/sshpass"<<"-p"<<"'password'"<<"ssh"<<"-o"<<"StrictHostKeyChecking=no"<<"-p"<<"22"<<"-l"<<"user\""<<"192.168.10.10:/abc/"<<"/def/");
    

    ( I get output: unexpected remote args: 192.168.10.10:/abc/ )

    J 1 Reply Last reply 1 May 2022, 11:55
    0
    • T TomNow99
      1 May 2022, 11:38

      Hi,

      I would like to use Rsync in QT. When I run this line in command line, it works:

      rsync -vr --rsh="/usr/bin/sshpass -p 'password' ssh -o StrictHostKeyChecking=no -p 22 -l user" 192.168.10.10:/abc/ /def/
      

      So in Qt I do the same:

      process->start("rsync -vr --rsh=\"/usr/bin/sshpass -p 'password' ssh -o StrictHostKeyChecking=no -p 22 -l user\" 192.168.10.10:/abc/ /def/", args);
      // args is empty QStringList()
      

      And this doesn't work.

      I find simillar topic:
      https://forum.qt.io/topic/127028/unable-to-run-qprocess-with-sshpass-in-windows

      So I try:

      process->start("rsync", QStringList()<<"-vr"<<"--rsh=\"/usr/bin/sshpass -p 'password' ssh -o StrictHostKeyChecking=no -p 22 -l user\""<<"192.168.10.10:/abc/"<<"/def/");
      

      ( I get output: Rsync: Failed to exec /usr/bin/sshpass -p 'password' ssh -o StrictHostKeyChecking=no -p 22 -l user No such file or directory

      And I try something like:

      process->start("rsync", QStringList()<<"-vr"<<"--rsh=\"/usr/bin/sshpass"<<"-p"<<"'password'"<<"ssh"<<"-o"<<"StrictHostKeyChecking=no"<<"-p"<<"22"<<"-l"<<"user\""<<"192.168.10.10:/abc/"<<"/def/");
      

      ( I get output: unexpected remote args: 192.168.10.10:/abc/ )

      J Offline
      J Offline
      JonB
      wrote on 1 May 2022, 11:55 last edited by JonB 5 Jan 2022, 11:56
      #2

      @TomNow99 said in Rsync, sshpass and QProcess:

      process->start("rsync -vr --rsh=\"/usr/bin/sshpass -p 'password' ssh -o StrictHostKeyChecking=no -p 22 -l user\" 192.168.10.10:/abc/ /def/", args);

      This won't work: nowadays QProcess::start() does not accept a single, command-line string to execute, you must pass just the executable as the first parameter and a QStringList of the arguments as the second parameter.

      Your second two attempts are along the right lines, but doubtless you have something wrong with the separation/quoting of your arguments.

      The whole of your --rsh="/usr/bin/sshpass -p 'password' ssh -o StrictHostKeyChecking=no -p 22 -l user" looks like a single command-line argument to me. But I don't think you want the "s around it, which your command shell was dealing with. I think you want:

      process->start("rsync",  QStringList()
          << "-vr"
          << "--rsh=/usr/bin/sshpass -p 'password' ssh -o StrictHostKeyChecking=no -p 22 -l user"
          << "192.168.10.10:/abc/"
          << "/def/");
      

      ?

      1 Reply Last reply
      2
      • T Offline
        T Offline
        TomNow99
        wrote on 1 May 2022, 12:02 last edited by
        #3

        @JonB It works! Thank you :)

        Could you tell me, when QProcess::start() was changed to not accept a single command-line string?

        J 1 Reply Last reply 1 May 2022, 12:50
        0
        • T TomNow99
          1 May 2022, 12:02

          @JonB It works! Thank you :)

          Could you tell me, when QProcess::start() was changed to not accept a single command-line string?

          J Offline
          J Offline
          JonB
          wrote on 1 May 2022, 12:50 last edited by JonB 5 Jan 2022, 12:53
          #4

          @TomNow99
          At 5.6-ish I think. See the current QT_NO_PROCESS_COMBINED_ARGUMENT_START. There is an obsolete void QProcess::start(const QString &command, QIODevice::OpenMode mode = ReadWrite).

          However, they factored out the internal code which must have been used to split the single-string parameter, so you can now call QStringList QProcess::splitCommand(QStringView command); requires Qt 5.15.

          Note that under Linux you can still run a "string" via:

          process.start("/bin/sh" /*or /bin/bash*/,  QStringList() << "-c" << "echo 'hello' | wc && echo \" This is a long line with \\$PATH=$PATH\" ");
          

          or similar. You are going via /bin/sh -c "...", which has its own quoting rules you must abide by.... We could have done your command that way, but between the sh -c quoting, the various quotings in your command, and doing it from C++ literals with \s & "s it might have been a worse brain-ache than my suggestion you took, which actually hopefully is quite "clean" :)

          1 Reply Last reply
          2

          1/4

          1 May 2022, 11:38

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved