-1

プロジェクトの背景->Linux組み込みシステムをリモートでアップグレードする必要があります。これには、tarボールファイルをWindowsQtアプリケーションからイーサネットケーブルで接続されたLinuxボックスに転送する必要があります。LinuxボックスのIPアドレスは固定されています。

これまでに行ったこと->Qtの完全な初心者であるため、ファイルを参照してtarボールファイルを確認するためのダイアログボックスを作成しました。

問題->[アップグレード]などの別のボタンをクリックすると、ファイルをWindowsからLinuxボックス(IPアドレスが固定されている)に転送し、さまざまなファイルをアップグレードする方法をコード化したbashスクリプトを実行する必要があります。

WindowsからLinuxボックスにファイルを送信する方法を教えてください。QtのFTPクライアントを見ましたが、ファイルを転送するのではなくダウンロードするのではないかと思います。

ありがとう、よろしく、
サム

4

2 に答える 2

1

QFtpクラスとQNetworkAccessManagerクラスはどちらも、FTPサーバーにファイルをアップロードできます。QNetworkAccessManagerクラスは、QFtpよりもあなたの仕事にさらに適しています。ただし、Linuxボックスで特定の設定が必要になります。
TCPソケット接続を使用してファイルを転送することもできます(クラスQTcpServerおよびQTcpSocketを参照)。これには、Linuxで実行されている追加のアプリケーションも必要です。したがって、プロセスを自動化したい場合は、Linuxボックスで実行されているFTPサーバーにファイルをアップロードする1つのQtアプリケーションを作成するか、クライアントとサーバーとして機能する2つの単純なアプリケーションを作成することができます。

于 2012-06-06T12:17:49.347 に答える
0

1)私のバッチスクリプトによると、upgrade.batはIPアドレス、アップグレードtarボールなどの2つのパラメーターを受け入れ、putty.exeを使用して、イーサネットケーブルで接続されたLinuxマシンにファイルを転送します。
バットスクリプトの例

pscp -pw "blabla" "%TARGET_UPDATE_FILE%" user @ "%TARGET_IP%": "%BASE_DIR%" /

ここで、target_update_file = tarボールファイルはQtから受け入れ、target ip=ipアドレスはqtからbatファイルへのパラメーターとして受信されます。

今qtで、アップグレードボタンコードで

void Qt_test::ReadOut()     
{       
     QProcess *processInfo = dynamic_cast< QProcess* >( sender() );

   if( processInfo )
     {
       ui->upgrade_info->append( processInfo->readAllStandardOutput() );
     }        
 }    

void Qt_test::ReadError()
{
     QProcess *processInfo = dynamic_cast< QProcess* >( sender() );

    if( processInfo )
   {
       ui->upgrade_info->append( processInfo->readAllStandardError() );
   }
 }

void Qt_test::on_file_browse_clicked()
{
     ui->selected_file->setText( QFileDialog::getOpenFileName( this, tr( "Open File" ),
                                                        "/home",
                                                        tr( "Upgrade file ( *.tar.gz )"     ) ) );
 }

void  Qt_test::on_file_upgrade_clicked()
 {
        QFileInfo upgradeFileInfo( ui->selected_file->text() );
        if( !upgradeFileInfo.exists() )
       {
             QMessageBox::information( this, tr( "Information" ),
                             tr( "Unable to find file for upgrading!" ) );
            return;
       }     

    QString batchPath= QDir::currentPath() + "\\testUpgrade.bat" ;
    QFileInfo batchFile( batchPath ) ;
    if( !batchFile.exists() )
    {
             QMessageBox::information( this, tr( "Information" ),
                             tr("Failed to find the upgrade batch file....... ") ) ;
         return;
     }

    //Check if cmd.exe is present in Clients system and is located at correct path
       QFileInfo cmdFile( "C:\\Windows\\system32\\cmd.exe");
     if( !cmdFile.exists() )
      {
           QMessageBox::information( this, tr( "Information" ),
                             tr("Failed to find the cmd.exe ... Check cmd.exe is   installed and is in  C:\\Windows\\system32\\ !") ) ;
          return;
      }

     QFileInfo puttyFile( "C:\\Windows\\system32\\putty.exe");
     if( !puttyFile.exists() )
     {
           QMessageBox::information( this, tr( "Information" ),
                              tr("Failed to find the putty.exe ... Check putty.exe(ideally version 0.62.0.0) is installed and is in  C:\\Windows\\system32\\ !") ) ;
          return;
     }

      QFileInfo plinkFile( "C:\\Windows\\system32\\plink.exe");
     if( !plinkFile.exists() )
     {
          QMessageBox::information( this, tr( "Information" ),
                              tr("Failed to find the plink.exe ... Check plink.exe(ideally version 0.62.0.0) is installed and is in  C:\\Windows\\system32\\ !") ) ;
          return;
     }

    QString upgradeFile =   upgradeFileInfo.absoluteFilePath();
   QString ipAddress   =   ui->selected_ip->text();
    qDebug() << " checksum valu is " <<checkSum.count() ;
    QStringList arguments ;

    arguments << " /c" << batchFile.absoluteFilePath()<< upgradeFile << ipAddress ;
   // copying update
   QProcess *processUpgrade = new QProcess( this );
   if( processUpgrade )
    {   std::cout <<" starting to upgrade " << std::endl ;

       processUpgrade->setEnvironment( QProcess::systemEnvironment() )  ;
       processUpgrade->setProcessChannelMode( QProcess::MergedChannels ) ;

        processUpgrade->start( cmdFile.absoluteFilePath(), arguments ) ;
        processUpgrade->waitForStarted() ;
        connect( processUpgrade, SIGNAL( readyReadStandardOutput() ), this, SLOT( ReadOut() ) ) ;
          connect( processUpgrade, SIGNAL( readyReadStandardError()  ), this, SLOT( ReadErr() ) ) ;
  }
 }
于 2012-06-20T15:05:49.300 に答える