Able to get file SFTP on command line, but not using Qt Class QProcess (solved)
-
i am using ubuntu desktop and is able to SFTP on the command line.
But not on Qt.Below is my debug message
"sftp 127.0.0.1"
"bash: line1: get: command not found"
Please advice.@
void MainWindow::getFuntion()
{
QProcess myProcess;
QByteArray result;char* ipset="127.0.0.1"; QString cmd= QString("sftp %1").arg(ipset); qDebug()<<cmd; //command string myProcess.setReadChannel(QProcess::StandardOutput); myProcess.setProcessChannelMode(QProcess::MergedChannels); myProcess.start("bash"); if(!myProcess.waitForStarted()){ qDebug()<<"Error: could not start terminal ::"<<endl; }
// myProcess.write("passwrod");
myProcess.write("get asd.txt");
myProcess.closeWriteChannel(); //done writing.while(myProcess.state()!=QProcess::NotRunning){ myProcess.waitForFinished(); result=myProcess.readAll(); qDebug()<<result; }
}
@ -
You are not using the cmd variable anywhere in this code, only for printing. So what you effectively do in the process is this:
@
bash
get asd.txt
@And so bash complains it does not understand "get" command. You should either run sftp directly, or pass it first, before passing "get".
-
it work when the below code is edited.
myProcess.start(cmd);OpenSSH prompted for password, is it possible to write the password in code first?
without the pc prompting for password?
myProcess.write("password"); -
Some info can be found here: "link":http://serverfault.com/questions/74158/how-can-you-do-a-one-liner-with-sftp-to-login-with-the-password-on-the-same-line