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. request about scp command (QProcess) using qt
Forum Updated to NodeBB v4.3 + New Features

request about scp command (QProcess) using qt

Scheduled Pinned Locked Moved Unsolved General and Desktop
29 Posts 4 Posters 4.2k Views 2 Watching
  • 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.
  • H Offline
    H Offline
    hlowd
    wrote on last edited by
    #1

    I am writing a Windows -> Linux scp file transfer code using qt.

    Simple commands such as ipconfig and ping work, but the scp command does not.
    When using the ipconfig, ping command, the nRet value is 0, and when using the scp command, the nRet value is -2.
    What part can I fix?

    ps) This command operates normally in the Windows cmd window.

    Below is the full code.
    QString command = ui->m_edit->text();

    QProcess* process = new QProcess(this);

    // command - ipconfig /all
    // command - ping xxx.xxx.xxx.xxx
    // command - scp [file] [remote name]@[remote ip]:[remote path]

    • ex) "scp file.ini user@192.168.0.1:\home\user\path"

    int nRet = process->execute(command);
    //process->start(command);

    QByteArray result = process->readAll();

    QMessageBox msgbx;
    msgbx.setText(result);
    msgbx.exec();

    jsulmJ JonBJ 2 Replies Last reply
    0
    • H hlowd

      I am writing a Windows -> Linux scp file transfer code using qt.

      Simple commands such as ipconfig and ping work, but the scp command does not.
      When using the ipconfig, ping command, the nRet value is 0, and when using the scp command, the nRet value is -2.
      What part can I fix?

      ps) This command operates normally in the Windows cmd window.

      Below is the full code.
      QString command = ui->m_edit->text();

      QProcess* process = new QProcess(this);

      // command - ipconfig /all
      // command - ping xxx.xxx.xxx.xxx
      // command - scp [file] [remote name]@[remote ip]:[remote path]

      • ex) "scp file.ini user@192.168.0.1:\home\user\path"

      int nRet = process->execute(command);
      //process->start(command);

      QByteArray result = process->readAll();

      QMessageBox msgbx;
      msgbx.setText(result);
      msgbx.exec();

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @hlowd Please format your code properly, it is hard to read.
      How does the command look exactly?
      Keep in mind that you have to pass the executable and its parameters as extra parameters to QProcess::start as shown in documentation. And please add error handling to see what goes wrong.
      Another comment: you're doing readAll() just after executing the command. This is not going to work. Either use waitForReadyRead or (better) connect a slot to readyRead signal and call readAll there.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • H hlowd

        I am writing a Windows -> Linux scp file transfer code using qt.

        Simple commands such as ipconfig and ping work, but the scp command does not.
        When using the ipconfig, ping command, the nRet value is 0, and when using the scp command, the nRet value is -2.
        What part can I fix?

        ps) This command operates normally in the Windows cmd window.

        Below is the full code.
        QString command = ui->m_edit->text();

        QProcess* process = new QProcess(this);

        // command - ipconfig /all
        // command - ping xxx.xxx.xxx.xxx
        // command - scp [file] [remote name]@[remote ip]:[remote path]

        • ex) "scp file.ini user@192.168.0.1:\home\user\path"

        int nRet = process->execute(command);
        //process->start(command);

        QByteArray result = process->readAll();

        QMessageBox msgbx;
        msgbx.setText(result);
        msgbx.exec();

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @hlowd Your literal C++ string "scp file.ini user@192.168.0.1:\home\user\path" has single backslashes in it.

        H 1 Reply Last reply
        2
        • JonBJ JonB

          @hlowd Your literal C++ string "scp file.ini user@192.168.0.1:\home\user\path" has single backslashes in it.

          H Offline
          H Offline
          hlowd
          wrote on last edited by
          #4
          This post is deleted!
          1 Reply Last reply
          0
          • H Offline
            H Offline
            hlowd
            wrote on last edited by
            #5

            @JonB
            hello.

            In the actual code, I entered two backslashes.

            Additionally, by using the exeexcute function rather than the start function, no additional parameters were entered, and a response was received immediately.

            Only the scp command did not work.

            jsulmJ H 2 Replies Last reply
            0
            • H hlowd

              @JonB
              hello.

              In the actual code, I entered two backslashes.

              Additionally, by using the exeexcute function rather than the start function, no additional parameters were entered, and a response was received immediately.

              Only the scp command did not work.

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @hlowd said in request about scp command (QProcess) using qt:

              In the actual code, I entered two backslashes

              Please post real code you're using to avoid such confusion.
              "Only the scp command did not work" - so does it work now or not?
              Did you add error handling as suggested?

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • H hlowd

                @JonB
                hello.

                In the actual code, I entered two backslashes.

                Additionally, by using the exeexcute function rather than the start function, no additional parameters were entered, and a response was received immediately.

                Only the scp command did not work.

                H Offline
                H Offline
                hlowd
                wrote on last edited by hlowd
                #7

                @hlowd

                This is the original source code.
                What's wrong?

                ps) I added two backslashes to the content, but only one is visible.

                //-----------------------------------
                // header
                //-----------------------------------
                #ifndef MAINWINDOW_H
                #define MAINWINDOW_H

                #include <QMainWindow>
                #include <QProcess>

                QT_BEGIN_NAMESPACE
                namespace Ui { class MainWindow; }
                QT_END_NAMESPACE

                class MainWindow : public QMainWindow
                {
                Q_OBJECT

                public:
                MainWindow(QWidget *parent = nullptr);
                ~MainWindow();
                QProcess *m_process;

                private slots:
                void on_pushButton_clicked();
                void readOutput();

                private:
                Ui::MainWindow *ui;
                };
                #endif // MAINWINDOW_H

                //----------------------------------------
                //cpp
                //-----------------------------------------
                #include "mainwindow.h"
                #include "ui_mainwindow.h"
                #include <qDebug>

                MainWindow::MainWindow(QWidget *parent)
                : QMainWindow(parent)
                , ui(new Ui::MainWindow)
                {
                ui->setupUi(this);
                }

                MainWindow::~MainWindow()
                {
                delete ui;
                }

                void MainWindow::on_pushButton_clicked()
                {
                m_process = new QProcess(this);
                QStringList listArguments;

                #if 0
                QString strParam = "scp";
                listArguments << "D:\SVN\Work\test\a.ini user@192.168.1.250:\home\user\SW\";
                #else
                QString strParam = "ipconfig";
                listArguments << "/all";
                #endif
                connect(m_process, SIGNAL(readyReadStandardError()), this, SLOT(readOutput()));
                connect(m_process, SIGNAL(readyReadStandardOutput()), this, SLOT(readOutput()));
                connect(m_process, SIGNAL(errorOccurred()), this, SLOT(readOutput()));

                m_process->start(strParam, listArguments);
                m_process->waitForFinished();
                
                if(m_process)
                    delete m_process;
                

                }

                void MainWindow::readOutput()
                {
                QString StdOut = m_process->readAllStandardOutput();
                QString StdError = m_process->readAllStandardError();
                QString StdError1 = m_process->errorString();
                qDebug() << "======================================\n";
                qDebug() << StdOut;
                qDebug() << StdError;
                qDebug() << StdError1;
                qDebug() << "======================================\n";
                }

                jsulmJ H 2 Replies Last reply
                0
                • H hlowd

                  @hlowd

                  This is the original source code.
                  What's wrong?

                  ps) I added two backslashes to the content, but only one is visible.

                  //-----------------------------------
                  // header
                  //-----------------------------------
                  #ifndef MAINWINDOW_H
                  #define MAINWINDOW_H

                  #include <QMainWindow>
                  #include <QProcess>

                  QT_BEGIN_NAMESPACE
                  namespace Ui { class MainWindow; }
                  QT_END_NAMESPACE

                  class MainWindow : public QMainWindow
                  {
                  Q_OBJECT

                  public:
                  MainWindow(QWidget *parent = nullptr);
                  ~MainWindow();
                  QProcess *m_process;

                  private slots:
                  void on_pushButton_clicked();
                  void readOutput();

                  private:
                  Ui::MainWindow *ui;
                  };
                  #endif // MAINWINDOW_H

                  //----------------------------------------
                  //cpp
                  //-----------------------------------------
                  #include "mainwindow.h"
                  #include "ui_mainwindow.h"
                  #include <qDebug>

                  MainWindow::MainWindow(QWidget *parent)
                  : QMainWindow(parent)
                  , ui(new Ui::MainWindow)
                  {
                  ui->setupUi(this);
                  }

                  MainWindow::~MainWindow()
                  {
                  delete ui;
                  }

                  void MainWindow::on_pushButton_clicked()
                  {
                  m_process = new QProcess(this);
                  QStringList listArguments;

                  #if 0
                  QString strParam = "scp";
                  listArguments << "D:\SVN\Work\test\a.ini user@192.168.1.250:\home\user\SW\";
                  #else
                  QString strParam = "ipconfig";
                  listArguments << "/all";
                  #endif
                  connect(m_process, SIGNAL(readyReadStandardError()), this, SLOT(readOutput()));
                  connect(m_process, SIGNAL(readyReadStandardOutput()), this, SLOT(readOutput()));
                  connect(m_process, SIGNAL(errorOccurred()), this, SLOT(readOutput()));

                  m_process->start(strParam, listArguments);
                  m_process->waitForFinished();
                  
                  if(m_process)
                      delete m_process;
                  

                  }

                  void MainWindow::readOutput()
                  {
                  QString StdOut = m_process->readAllStandardOutput();
                  QString StdError = m_process->readAllStandardError();
                  QString StdError1 = m_process->errorString();
                  qDebug() << "======================================\n";
                  qDebug() << StdOut;
                  qDebug() << StdError;
                  qDebug() << StdError1;
                  qDebug() << "======================================\n";
                  }

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @hlowd said in request about scp command (QProcess) using qt:

                  listArguments << "D:\SVN\Work\test\a.ini user@192.168.1.250:\home\user\SW";

                  Is this really your real code?!
                  You again have single back-slashes.
                  And why do you use back-slashes for paths on Linux side?
                  Also that line should be:

                  listArguments << "D:\\SVN\\Work\\test\\a.ini" <<  "user@192.168.1.250:/home/user/SW/";
                  

                  And please format you code properly.

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  1
                  • H hlowd

                    @hlowd

                    This is the original source code.
                    What's wrong?

                    ps) I added two backslashes to the content, but only one is visible.

                    //-----------------------------------
                    // header
                    //-----------------------------------
                    #ifndef MAINWINDOW_H
                    #define MAINWINDOW_H

                    #include <QMainWindow>
                    #include <QProcess>

                    QT_BEGIN_NAMESPACE
                    namespace Ui { class MainWindow; }
                    QT_END_NAMESPACE

                    class MainWindow : public QMainWindow
                    {
                    Q_OBJECT

                    public:
                    MainWindow(QWidget *parent = nullptr);
                    ~MainWindow();
                    QProcess *m_process;

                    private slots:
                    void on_pushButton_clicked();
                    void readOutput();

                    private:
                    Ui::MainWindow *ui;
                    };
                    #endif // MAINWINDOW_H

                    //----------------------------------------
                    //cpp
                    //-----------------------------------------
                    #include "mainwindow.h"
                    #include "ui_mainwindow.h"
                    #include <qDebug>

                    MainWindow::MainWindow(QWidget *parent)
                    : QMainWindow(parent)
                    , ui(new Ui::MainWindow)
                    {
                    ui->setupUi(this);
                    }

                    MainWindow::~MainWindow()
                    {
                    delete ui;
                    }

                    void MainWindow::on_pushButton_clicked()
                    {
                    m_process = new QProcess(this);
                    QStringList listArguments;

                    #if 0
                    QString strParam = "scp";
                    listArguments << "D:\SVN\Work\test\a.ini user@192.168.1.250:\home\user\SW\";
                    #else
                    QString strParam = "ipconfig";
                    listArguments << "/all";
                    #endif
                    connect(m_process, SIGNAL(readyReadStandardError()), this, SLOT(readOutput()));
                    connect(m_process, SIGNAL(readyReadStandardOutput()), this, SLOT(readOutput()));
                    connect(m_process, SIGNAL(errorOccurred()), this, SLOT(readOutput()));

                    m_process->start(strParam, listArguments);
                    m_process->waitForFinished();
                    
                    if(m_process)
                        delete m_process;
                    

                    }

                    void MainWindow::readOutput()
                    {
                    QString StdOut = m_process->readAllStandardOutput();
                    QString StdError = m_process->readAllStandardError();
                    QString StdError1 = m_process->errorString();
                    qDebug() << "======================================\n";
                    qDebug() << StdOut;
                    qDebug() << StdError;
                    qDebug() << StdError1;
                    qDebug() << "======================================\n";
                    }

                    H Offline
                    H Offline
                    hlowd
                    wrote on last edited by
                    #9

                    @hlowd

                    I entered two words in the post, but only one is displayed on the screen...

                    jsulmJ H 2 Replies Last reply
                    0
                    • H hlowd

                      @hlowd

                      I entered two words in the post, but only one is displayed on the screen...

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @hlowd said in request about scp command (QProcess) using qt:

                      I entered two words in the post, but only one is displayed on the screen...

                      Use code tags properly, then it will be shown correctly

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • H hlowd

                        @hlowd

                        I entered two words in the post, but only one is displayed on the screen...

                        H Offline
                        H Offline
                        hlowd
                        wrote on last edited by
                        #11

                        @hlowd

                        listArguments << "D:\\SVN\\Work\\test\\a.ini" << "user@192.168.1.250:/home/user/SW/";

                        Even though I entered it like this, it is the same.
                        The response from start comes immediately, but the readOutput function is not called.

                        jsulmJ H 2 Replies Last reply
                        0
                        • H hlowd

                          @hlowd

                          listArguments << "D:\\SVN\\Work\\test\\a.ini" << "user@192.168.1.250:/home/user/SW/";

                          Even though I entered it like this, it is the same.
                          The response from start comes immediately, but the readOutput function is not called.

                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          @hlowd said in request about scp command (QProcess) using qt:

                          but the readOutput function is not called

                          Probably because you're deleting m_process right after waitForFinished.
                          Are you sure scp.exe command is found?
                          Try with an absolute path to scp.exe to make sure it is actually found.

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          0
                          • H hlowd

                            @hlowd

                            listArguments << "D:\\SVN\\Work\\test\\a.ini" << "user@192.168.1.250:/home/user/SW/";

                            Even though I entered it like this, it is the same.
                            The response from start comes immediately, but the readOutput function is not called.

                            H Offline
                            H Offline
                            hlowd
                            wrote on last edited by
                            #13

                            @hlowd

                            The symptom is the same even if delete is not called.

                            If it is a command instruction rather than a code, the instruction will be executed normally.
                            The file is moved normally. (Windows -> Linux)

                            jsulmJ H 2 Replies Last reply
                            0
                            • H hlowd

                              @hlowd

                              The symptom is the same even if delete is not called.

                              If it is a command instruction rather than a code, the instruction will be executed normally.
                              The file is moved normally. (Windows -> Linux)

                              jsulmJ Offline
                              jsulmJ Offline
                              jsulm
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              @hlowd Again: try with absolute path to scp.exe

                              https://forum.qt.io/topic/113070/qt-code-of-conduct

                              1 Reply Last reply
                              0
                              • H hlowd

                                @hlowd

                                The symptom is the same even if delete is not called.

                                If it is a command instruction rather than a code, the instruction will be executed normally.
                                The file is moved normally. (Windows -> Linux)

                                H Offline
                                H Offline
                                hlowd
                                wrote on last edited by hlowd
                                #15

                                @hlowd
                                There are files in that path.

                                C:\Windows\WinSxS\amd64_openssh-common-components-onecore_31bf3856ad364e35_10.0.22621.1_none_1e3c4880a37d88bb
                                
                                scp.exe
                                ssh-add.exe
                                ssh-agent.exe
                                ssh-keygen.exe
                                

                                // new code

                                QString strParam = "C:\\Windows\\WinSxS\\amd64_openssh-common-components-onecore_31bf3856ad364e35_10.0.22621.1_none_1e3c4880a37d88bb\\scp.exe";
                                

                                // error message

                                "CreateProcessW failed error:2 posix_spawn: No such file or directory"
                                
                                JonBJ jsulmJ 2 Replies Last reply
                                0
                                • H hlowd

                                  @hlowd
                                  There are files in that path.

                                  C:\Windows\WinSxS\amd64_openssh-common-components-onecore_31bf3856ad364e35_10.0.22621.1_none_1e3c4880a37d88bb
                                  
                                  scp.exe
                                  ssh-add.exe
                                  ssh-agent.exe
                                  ssh-keygen.exe
                                  

                                  // new code

                                  QString strParam = "C:\\Windows\\WinSxS\\amd64_openssh-common-components-onecore_31bf3856ad364e35_10.0.22621.1_none_1e3c4880a37d88bb\\scp.exe";
                                  

                                  // error message

                                  "CreateProcessW failed error:2 posix_spawn: No such file or directory"
                                  
                                  JonBJ Offline
                                  JonBJ Offline
                                  JonB
                                  wrote on last edited by JonB
                                  #16

                                  @hlowd
                                  If you want help on this, at least for my part, please make the effort to enclose your code blocks and literal extracts in the forums block quotes (</> button) as we have asked several times. It does not require much effort on your side.

                                  By now you should be trying a command of scp, nothing else, no arguments, to verify that (a) it is found and can be run and (b) you can successfully read any output from it, e.g. presumably a "usage" message in this case.

                                  1 Reply Last reply
                                  0
                                  • H hlowd

                                    @hlowd
                                    There are files in that path.

                                    C:\Windows\WinSxS\amd64_openssh-common-components-onecore_31bf3856ad364e35_10.0.22621.1_none_1e3c4880a37d88bb
                                    
                                    scp.exe
                                    ssh-add.exe
                                    ssh-agent.exe
                                    ssh-keygen.exe
                                    

                                    // new code

                                    QString strParam = "C:\\Windows\\WinSxS\\amd64_openssh-common-components-onecore_31bf3856ad364e35_10.0.22621.1_none_1e3c4880a37d88bb\\scp.exe";
                                    

                                    // error message

                                    "CreateProcessW failed error:2 posix_spawn: No such file or directory"
                                    
                                    jsulmJ Offline
                                    jsulmJ Offline
                                    jsulm
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #17

                                    @hlowd said in request about scp command (QProcess) using qt:

                                    Can I do it this way?

                                    Yes, just try.
                                    I would also execute scp using this absolute path in a terminal to make sure it works.

                                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                                    H 1 Reply Last reply
                                    0
                                    • jsulmJ jsulm

                                      @hlowd said in request about scp command (QProcess) using qt:

                                      Can I do it this way?

                                      Yes, just try.
                                      I would also execute scp using this absolute path in a terminal to make sure it works.

                                      H Offline
                                      H Offline
                                      hlowd
                                      wrote on last edited by
                                      #18

                                      @jsulm

                                      There are files in that path.

                                      C:\Windows\WinSxS\amd64_openssh-common-components-onecore_31bf3856ad364e35_10.0.22621.1_none_1e3c4880a37d88bb
                                      
                                      scp.exe
                                      ssh-add.exe
                                      ssh-agent.exe
                                      ssh-keygen.exe
                                      

                                      // new code

                                      QString strParam = "C:\\Windows\\WinSxS\\amd64_openssh-common-components-onecore_31bf3856ad364e35_10.0.22621.1_none_1e3c4880a37d88bb\\scp.exe";
                                      

                                      // error message

                                      "CreateProcessW failed error:2 posix_spawn: No such file or directory"
                                      

                                      The same error occurs in the command prompt.

                                      JonBJ jsulmJ 2 Replies Last reply
                                      0
                                      • H hlowd

                                        @jsulm

                                        There are files in that path.

                                        C:\Windows\WinSxS\amd64_openssh-common-components-onecore_31bf3856ad364e35_10.0.22621.1_none_1e3c4880a37d88bb
                                        
                                        scp.exe
                                        ssh-add.exe
                                        ssh-agent.exe
                                        ssh-keygen.exe
                                        

                                        // new code

                                        QString strParam = "C:\\Windows\\WinSxS\\amd64_openssh-common-components-onecore_31bf3856ad364e35_10.0.22621.1_none_1e3c4880a37d88bb\\scp.exe";
                                        

                                        // error message

                                        "CreateProcessW failed error:2 posix_spawn: No such file or directory"
                                        

                                        The same error occurs in the command prompt.

                                        JonBJ Offline
                                        JonBJ Offline
                                        JonB
                                        wrote on last edited by
                                        #19

                                        @hlowd
                                        I am not a total Windows expert, but I did not think you should ever attempt to run anything in the WinSxS area? You should be running the scp which is on your PATH (presumably).

                                        1 Reply Last reply
                                        0
                                        • H hlowd

                                          @jsulm

                                          There are files in that path.

                                          C:\Windows\WinSxS\amd64_openssh-common-components-onecore_31bf3856ad364e35_10.0.22621.1_none_1e3c4880a37d88bb
                                          
                                          scp.exe
                                          ssh-add.exe
                                          ssh-agent.exe
                                          ssh-keygen.exe
                                          

                                          // new code

                                          QString strParam = "C:\\Windows\\WinSxS\\amd64_openssh-common-components-onecore_31bf3856ad364e35_10.0.22621.1_none_1e3c4880a37d88bb\\scp.exe";
                                          

                                          // error message

                                          "CreateProcessW failed error:2 posix_spawn: No such file or directory"
                                          

                                          The same error occurs in the command prompt.

                                          jsulmJ Offline
                                          jsulmJ Offline
                                          jsulm
                                          Lifetime Qt Champion
                                          wrote on last edited by
                                          #20

                                          @hlowd Did scp executable ever work for you in terminal? The path where it is located looks strange, don't know from where it comes. On my machine I have it here: c:\windows\System32\OpenSSH\scp.exe

                                          You can check where your scp.exe is located using this command:

                                          where scp
                                          

                                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                                          H 1 Reply Last reply
                                          2

                                          • Login

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