Question

How can I use QProcess for Command Line Interactive arguments, I am trying to a transfer a file usimg scp which prompts for password

QString program = "c:/temp/pscp.exe";
QStringList arguments;
arguments << "C:/Users/polaris8/Desktop/Test1GB.zip" <<   "Mrigendra@192.168.26.142:/home/";
QPointer<QProcess> myProcess;
myProcess = new QProcess;
connect(myProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(readOutput()));
myProcess->start(program , arguments);

After this the commnad Line asks for Password how to satisfy it using QProcess , can I overcome it by giving some options in my arguments only for scp, or what should be the code in my slot readOutput that throws the password to Command Line . Any suggestions would be helpful. Thanks

Était-ce utile?

La solution 2

I think you can pass the username / password as options with:

-l user
-pw passwd

So your arguments should look like this:

QStringList arguments;
arguments << "-l" << "Mrigendra" << "-pw" << "Password" <<
             "C:/Users/polaris8/Desktop/Test1GB.zip" <<
             "192.168.26.142:/home/";

Autres conseils

It seems that scp does not have such options, but pscp (sftp client does have). So, I would be writing something like this to extend your initial arguments with that option based on the following man page:

QString program = "c:/temp/pscp.exe";
QStringList arguments;
arguments << "-pw" << "password" << "C:/Users/polaris8/Desktop/Test1GB.zip" << "Mrigendra@192.168.26.142:/home/";
             ^^^^^^^^^^^^^^^^^^^
QPointer<QProcess> myProcess;
myProcess = new QProcess;
connect(myProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(readOutput()));
myProcess->start(program , arguments);

Also, I would encourage you to use QStandardPaths for a path like yours. See the documentation for details:

QStandardPaths::DesktopLocation 0   Returns the user's desktop directory.

So, you could eventually replace this string:

"C:/Users/polaris8/Desktop/Test1GB.zip"

with the following:

QStandardPaths::locate(QStandardPaths::DesktopLocation, "Test1GB.zip")

That being said, you may wish to consider using keys instead of password in the future. It would be a bit more secure, and also convenient for your application.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top