コード例 #1
0
ファイル: mainwindow.cpp プロジェクト: Karalix/EasyFtpDrawer
void MainWindow::connectToFtp()
{
    ftp = new QFtp(this);
    connect(ftp, SIGNAL(commandFinished(int,bool)), this, SLOT(cmdFinished(int,bool)));
    connect(ftp, SIGNAL(listInfo(QUrlInfo)), this, SLOT(dlFile(QUrlInfo)));
    url = new QUrl(ui->adrEdit->text());

    if(!url->isValid() || url->scheme().toLower() != QLatin1String("ftp")){

        ftp->connectToHost(ui->adrEdit->text());
        ftp->login(ui->loginEdit->text(), ui->pwdEdit->text());

    } else {

        ftp->connectToHost(url->host(), url->port());

        ftp->login(ui->loginEdit->text(), ui->pwdEdit->text());
    }


}
コード例 #2
0
ファイル: main.c プロジェクト: ulia22/projetReseaux
/*
 * Permet de gérer une connection sur le socket sdClient dans un thread.
 */
void *manageClient(void* par[]) {
    pthread_t id_t = pthread_self();
    //Socket client
    int sdClient = ((acceptThreadArg*) par)->sock;
    struct sockaddr_in client_addr = ((acceptThreadArg*) par)->pair;
    char buffer[MSG_BUFFER_SIZE];
    int ret = 0;

    while (strncmp(buffer, "909", 3) != 0) {

        //Lecture du code du message.
        memset(buffer, 0, MSG_BUFFER_SIZE);
        ret = recv(sdClient, buffer, 3, 0);
        if (ret <= 0) {
            strcat(buffer, "909");
        }

        if (strncmp(buffer, "100", 3) == 0) {//Nouveau client
            if (initClientConnect(sdClient, client_addr) != 0) {
                printf("Erreur initClientConnect.\n");
                exit(EXIT_FAILURE);
            }
        } else if (strncmp(buffer, "200", 3) == 0) {//Partage d'un fichier
            if (shareFile(sdClient, client_addr) != 0) {
                printf("Erreur partage fichier.\n");
                exit(EXIT_FAILURE);
            }
        } else if (strncmp(buffer, "300", 3) == 0) {//DL d'un fichier
            if (dlFile(sdClient, client_addr) != 0) {
                printf("Erreur DL fichier.\n");
                exit(EXIT_FAILURE);
            }
        } else if (strncmp(buffer, "400", 3) == 0) {//Mise a jour meta-data

        }
    }
    //closesocket(sdClient);
    close(sdClient);
    pthread_exit((void*) id_t);
}
コード例 #3
0
void MainWindow::downloadFinished(QNetworkReply *reply)
{
    QScrollBar *sb = ui->textBrowser->verticalScrollBar();
    QUrl url = reply->url();

    if (reply->error()) {
      if ( !url.toString().contains("hgt.zip") ) {
        ui->textBrowser->append("Download of " + QString(url.toEncoded().constData()) + " failed: " + QString(reply->errorString()));
        sb->setValue(sb->maximum()); // get the info shown
      }

        QString fileUrl = url.toEncoded().constData();
    } else {
        QString path = url.path();
        QString fileName = QFileInfo(path).fileName();
        if (fileName.isEmpty()) fileName = "download";

        QDir dir(dataDirectory);
        dir.mkpath(dataDirectory);
        QFile file(dataDirectory+"/"+fileName);

        if (fileName.contains("dl")) {
            // obtain url
            QFile file(dataDirectory+"/"+fileName);
        } else if (fileName.contains("hgt")) {
            // obtain elevation files
            dir.mkpath(dataDirectory+"/SRTM-3/");
            file.setFileName(dataDirectory+"/SRTM-3/"+fileName);
            GUILog( url.toString() + "\n", "download" );
        }

        if (file.open(QIODevice::WriteOnly)) {
            file.write(reply->readAll());
            file.close();
        }

        // download actual shapefile package
        if (fileName.contains("dl")) {
            QFile dlFile(dataDirectory+"/"+fileName);
            if (!dlFile.open(QIODevice::ReadOnly | QIODevice::Text))
                return;
            QTextStream textStream( &dlFile);
            QString dlUrl = textStream.readAll();
            dlUrl.remove("<p>The document has moved <a href=\"");
            dlUrl.remove("\">here</a></p>\n");
            QNetworkReply *r = _manager->get(QNetworkRequest("http://mapserver.flightgear.org"+dlUrl));
            connect(r, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(downloadShapefilesProgressBar(qint64, qint64)));
        }

        ui->textBrowser->append("Download of "+QString(url.toEncoded().constData())+" succeded saved to: "+QString(fileName));
        sb->setValue(sb->maximum()); // get the info shown

        // unzip shapefile package
        if (fileName.contains("-")) {
            // unpack zip
            QString arguments;
#ifdef Q_OS_WIN
            arguments += "7z.exe x \""+dataDirectory+"/"+fileName+"\" -o\""+dataDirectory+"\" -aoa";
#endif
#ifdef Q_OS_UNIX
            arguments += "unzip -o "+dataDirectory+"/"+fileName+" -d "+dataDirectory;
#endif
            //ui->textBrowser->append(arguments);
            GUILog( arguments + "\n", "download" );
            QProcess proc;
            proc.start(arguments, QIODevice::ReadWrite);
            proc.waitForReadyRead();
            proc.waitForFinished(-1);

            // delete temporary files
            QFile shapeFile(dataDirectory+"/"+fileName);
            shapeFile.remove();
            QFile dlshpFile(dataDirectory+"/dlshp");
            dlshpFile.remove();

            // re-enable download button
            ui->downloadShapefilesButton->setText("Download shapefiles");
            ui->downloadShapefilesButton->setEnabled(1);
        }

        if (fileName.contains(".hgt.zip")){
            // adjust progress bar
            ui->downloadElevationProgressBar->setValue(ui->downloadElevationProgressBar->value()+1);
        }
    }
    // re-enable download button
    if (ui->downloadElevationProgressBar->value() == ui->downloadElevationProgressBar->maximum()) {
        ui->downloadElevationButton->setEnabled(1);
    }
}