bool FtpUpload::connectToHost(){ m_pFTPConnection = new QFtp(); connect(m_pFTPConnection,SIGNAL(stateChanged(int)),this,SLOT(stateChanged(int))); connect(m_pFTPConnection,SIGNAL(done(bool)),this,SLOT(commandDone(bool))); connect(m_pFTPConnection,SIGNAL(commandFinished(int,bool)),this,SLOT(commandFinished(int,bool))); connect(m_pFTPConnection,SIGNAL(dataTransferProgress(qint64,qint64)),this,SLOT(dataTransferProgress(qint64,qint64))); m_pFTPConnection->connectToHost("www.lightparc.com"); m_IDLogin = m_pFTPConnection->login(m_strUsername,m_strPassword); return true; }
//![0] void FtpWindow::connectOrDisconnect() { if (ftp) { ftp->abort(); ftp->deleteLater(); ftp = 0; //![0] fileList->setEnabled(false); cdToParentButton->setEnabled(false); downloadButton->setEnabled(false); connectButton->setEnabled(true); connectButton->setText(tr("Connect")); #ifndef QT_NO_CURSOR setCursor(Qt::ArrowCursor); #endif statusLabel->setText(tr("Please enter the name of an FTP server.")); return; } #ifndef QT_NO_CURSOR setCursor(Qt::WaitCursor); #endif //![1] ftp = new QFtp(this); connect(ftp, SIGNAL(commandFinished(int,bool)), this, SLOT(ftpCommandFinished(int,bool))); connect(ftp, SIGNAL(listInfo(QUrlInfo)), this, SLOT(addToList(QUrlInfo))); connect(ftp, SIGNAL(dataTransferProgress(qint64,qint64)), this, SLOT(updateDataTransferProgress(qint64,qint64))); fileList->clear(); currentPath.clear(); isDirectory.clear(); //![1] //![2] QUrl url(ftpServerLineEdit->text()); if (!url.isValid() || url.scheme().toLower() != QLatin1String("ftp")) { ftp->connectToHost(ftpServerLineEdit->text(), 21); ftp->login(); } else { ftp->connectToHost(url.host(), url.port(21)); if (!url.userName().isEmpty()) ftp->login(QUrl::fromPercentEncoding(url.userName().toLatin1()), url.password()); else ftp->login(); if (!url.path().isEmpty()) ftp->cd(url.path()); } //![2] fileList->setEnabled(true); connectButton->setEnabled(false); connectButton->setText(tr("Disconnect")); statusLabel->setText(tr("Connecting to FTP server %1...") .arg(ftpServerLineEdit->text())); }
void DownloadItem::startDownloadingFromFtp(const QUrl &url) { if (!m_outputFile.isOpen() && !m_outputFile.open(QIODevice::WriteOnly)) { stop(false); ui->downloadInfo->setText(tr("Error: Cannot write to file!")); return; } #if QTWEBENGINE_DISABLED m_ftpDownloader = new FtpDownloader(this); connect(m_ftpDownloader, SIGNAL(finished()), this, SLOT(finished())); connect(m_ftpDownloader, SIGNAL(dataTransferProgress(qint64,qint64)), this, SLOT(downloadProgress(qint64,qint64))); connect(m_ftpDownloader, SIGNAL(errorOccured(QFtp::Error)), this, SLOT(error())); connect(m_ftpDownloader, SIGNAL(ftpAuthenticationRequierd(QUrl,QAuthenticator*)), mApp->networkManager(), SLOT(ftpAuthentication(QUrl,QAuthenticator*))); m_ftpDownloader->download(url, &m_outputFile); m_downloading = true; m_timer.start(1000, this); QTimer::singleShot(200, this, SLOT(updateDownload())); if (m_ftpDownloader->error() != QFtp::NoError) { error(); } #endif }
void DownloadItem::startDownloadingFromFtp(const QUrl &url) { if (!outputFile_.isOpen() && !outputFile_.open(QIODevice::WriteOnly)) { stop(false); downloadInfo_->setText(tr("Error: Cannot write to file!")); return; } ftpDownloader_ = new FtpDownloader(this); connect(ftpDownloader_, SIGNAL(finished()), this, SLOT(finished())); connect(ftpDownloader_, SIGNAL(dataTransferProgress(qint64, qint64)), this, SLOT(downloadProgress(qint64, qint64))); connect(ftpDownloader_, SIGNAL(errorOccured(QFtp::Error)), this, SLOT(error())); connect(ftpDownloader_, SIGNAL(ftpAuthenticationRequierd(const QUrl &, QAuthenticator*)), mainApp->networkManager(), SLOT(ftpAuthentication(const QUrl &, QAuthenticator*))); ftpDownloader_->download(url, &outputFile_); downloading_ = true; updateInfoTimer_.start(1000); QTimer::singleShot(200, this, SLOT(updateDownload())); if (ftpDownloader_->error() != QFtp::NoError) { error(); } }
Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) { ui->setupUi(this); ui->ftpServerLineEdit->setText("192.168.12.128"); ui->userNameLineEdit->setText("dev"); ui->passWordLineEdit->setText("123"); ui->passWordLineEdit->setEchoMode(QLineEdit::Password); initiateUI(); // ui->label->clear(); ftp = new QFtp(this); connect(ui->fileListTreeWidget, SIGNAL(itemActivated(QTreeWidgetItem*,int)), this, SLOT(processItem(QTreeWidgetItem*,int))); connect(ftp, SIGNAL(commandStarted(int)), this, SLOT(ftpCommandStarted(int))); connect(ftp, SIGNAL(commandFinished(int,bool)), this, SLOT(ftpCommandFinished(int,bool))); connect(ftp, SIGNAL(listInfo(QUrlInfo)), this, SLOT(addToList(QUrlInfo))); connect(ftp, SIGNAL(dataTransferProgress(qint64,qint64)), this, SLOT(updateDataTransferProgress(qint64,qint64))); // ftp->connectToHost("192.168.12.128"); // ftp->login("dev", "123"); // ftp->cd("Documents"); // ftp->get("test"); // ftp->close(); }
void Q3LocalFs::operationPut( Q3NetworkOperation *op ) { #ifdef QLOCALFS_DEBUG qDebug( "Q3LocalFs: operationPut" ); #endif op->setState( StInProgress ); QString to = Q3Url( op->arg( 0 ) ).path(); QFile f( to ); if ( !f.open( IO_WriteOnly ) ) { QString msg = tr( "Could not write\n%1" ).arg( to ); op->setState( StFailed ); op->setProtocolDetail( msg ); op->setErrorCode( (int)ErrPut ); emit finished( op ); return; } QByteArray ba( op->rawArg( 1 ) ); emit dataTransferProgress( 0, ba.size(), op ); int blockSize = calcBlockSize( ba.size() ); if ( (int)ba.size() < blockSize ) { f.writeBlock( ba.data(), ba.size() ); emit dataTransferProgress( ba.size(), ba.size(), op ); } else { int i = 0; while ( i + blockSize < (int)ba.size() - 1 ) { if ( operationInProgress() != op ) return; f.writeBlock( &ba.data()[ i ], blockSize ); f.flush(); emit dataTransferProgress( i + blockSize, ba.size(), op ); i += blockSize; QPointer<QObject> that = this; qApp->processEvents(); if (!that) return; } if ( i < (int)ba.size() - 1 ) f.writeBlock( &ba.data()[ i ], ba.size() - i ); emit dataTransferProgress( ba.size(), ba.size(), op ); } op->setState( StDone ); f.close(); emit finished( op ); }
FTPUpdate::FTPUpdate(QString ftpHost, QString ftpDirectory, ArpmanetDC *parent) : QObject(parent) { //Constructor pParent = parent; pFtpDirectory = ftpDirectory; pFtpHost = ftpHost; downloadListIndex = -1; downloadGetIndex = -1; listIndex = -1; ftpServer = new QFtp(this); connect(ftpServer, SIGNAL(listInfo(const QUrlInfo &)), this, SLOT(listInfoReceived(const QUrlInfo &))); connect(ftpServer, SIGNAL(done(bool)), this, SLOT(ftpServerDone(bool))); connect(ftpServer, SIGNAL(commandFinished(int, bool)), this, SLOT(commandFinished(int, bool))); connect(ftpServer, SIGNAL(readyRead()), this, SLOT(readFromServer())); connect(ftpServer, SIGNAL(dataTransferProgress(qint64, qint64)), this, SIGNAL(dataTransferProgress(qint64, qint64))); }
FormFile::FormFile(QWidget *parent) : QWidget(parent),fileModel(new FtpDirModel()),ftpCommandId(0), sourceFile(NULL),removeCommand(new QAction(tr("删除"), this)), renameCommand(new QAction(tr("重命名"), this)), ui(new Ui::FormFile) { ui->setupUi(this); ui->lvServer->installEventFilter(this); ui->lvServer->setAcceptDrops(true); connect(removeCommand, SIGNAL(triggered()), this, SLOT(removeFile())); connect(renameCommand, SIGNAL(triggered()), this, SLOT(renameFile())); connect(&ftp, SIGNAL(commandFinished(int,bool)), this, SLOT(ftpCommandFinished(int,bool))); connect(&ftp, SIGNAL(dataTransferProgress(qint64,qint64)), this, SLOT(updateProgress(qint64,qint64))); }
DNetLoad::DNetLoad(QWidget *parent) : QDialog(parent) { showMaximized(); label=new QLabel(this); textBrowser=new QTextBrowser(); loadBtn=new QPushButton("下载"); tree=new QTreeWidget(); rootTree=new QTreeView(); progressBar=new QProgressBar(); QStringList list; list<<"name"<<"size"<<"owner"<<"group"<<"date"; tree->setHeaderLabels(list); tree->setColumnWidth(0,250); QDirModel *model = new QDirModel; rootTree->setModel(model); rootTree->setRootIndex(model->index("/")); rootTree->show(); rootTree->setColumnWidth(0,300); QGridLayout *layout=new QGridLayout(); layout->addWidget(tree,0,0,10,1); layout->addWidget(rootTree,0,1,18,1); layout->addWidget(loadBtn,10,0,1,1); layout->addWidget(textBrowser,11,0,5,1); layout->addWidget(progressBar,16,0); layout->addWidget(label,17,0); setLayout(layout); ftp = new QFtp(this); ftp->connectToHost("ftp.qt.nokia.com"); //连接到服务器 ftp->login(); //登录 ftp->cd("qt/source"); //跳转到“qt”目录下 ftp->list(); connect(ftp,SIGNAL(commandStarted(int)),this,SLOT(ftpCommandStarted(int))); //当每条命令开始执行时发出相应的信号 connect(ftp,SIGNAL(commandFinished(int,bool)),this,SLOT(ftpCommandFinished(int,bool))); connect(ftp,SIGNAL(listInfo(QUrlInfo)),this,SLOT(addToList(QUrlInfo))); connect(ftp,SIGNAL(dataTransferProgress(qint64,qint64)), this,SLOT(progressBar_update(qint64,qint64))); connect(rootTree,SIGNAL(clicked(QModelIndex)),this,SLOT(rootTree_click(QModelIndex))); connect(loadBtn,SIGNAL(clicked()),this,SLOT(loadBtn_click())); }
void MainWindow::connectFtp(QString ip, QString id, QString pwd) { //write info login->writeInfo(); connect(ftp, SIGNAL(listInfo(QUrlInfo)), this, SLOT(addToList(QUrlInfo))); connect(ftp, SIGNAL(commandFinished(int,bool)), this, SLOT(ftpCommandFinished(int,bool))); connect(ftp, SIGNAL(dataTransferProgress(qint64,qint64)), this, SLOT(updateDataTransferProgress(qint64,qint64))); ftp->connectToHost(ip, 21); //FIXME : port editable ftp->login(id, pwd); }
CFtpTransfer::CFtpTransfer(QObject *parent) : QObject(parent) { m_flagProcessOk=false; m_flagFtpOk=false; QString sFtpIp="ftp://"; m_url.setUrl(sFtpIp); connect(&m_ftp,SIGNAL(done(bool)),this,SLOT(slotFtpDone(bool))); connect(&m_ftp,SIGNAL(listInfo(const QUrlInfo&)),this,SLOT(slotListInfo(const QUrlInfo&))); connect(&m_ftp,SIGNAL(dataTransferProgress(qint64,qint64)),this,SLOT(slotDownloadProcess(qint64,qint64))); }
bool QNetworkProtocol::qt_emit( int _id, QUObject* _o ) { switch ( _id - staticMetaObject()->signalOffset() ) { case 0: data((const QByteArray&)*((const QByteArray*)static_QUType_ptr.get(_o+1)),(QNetworkOperation*)static_QUType_ptr.get(_o+2)); break; case 1: connectionStateChanged((int)static_QUType_int.get(_o+1),(const QString&)static_QUType_QString.get(_o+2)); break; case 2: finished((QNetworkOperation*)static_QUType_ptr.get(_o+1)); break; case 3: start((QNetworkOperation*)static_QUType_ptr.get(_o+1)); break; case 4: newChildren((const QValueList<QUrlInfo>&)*((const QValueList<QUrlInfo>*)static_QUType_ptr.get(_o+1)),(QNetworkOperation*)static_QUType_ptr.get(_o+2)); break; case 5: newChild((const QUrlInfo&)*((const QUrlInfo*)static_QUType_ptr.get(_o+1)),(QNetworkOperation*)static_QUType_ptr.get(_o+2)); break; case 6: createdDirectory((const QUrlInfo&)*((const QUrlInfo*)static_QUType_ptr.get(_o+1)),(QNetworkOperation*)static_QUType_ptr.get(_o+2)); break; case 7: removed((QNetworkOperation*)static_QUType_ptr.get(_o+1)); break; case 8: itemChanged((QNetworkOperation*)static_QUType_ptr.get(_o+1)); break; case 9: dataTransferProgress((int)static_QUType_int.get(_o+1),(int)static_QUType_int.get(_o+2),(QNetworkOperation*)static_QUType_ptr.get(_o+3)); break; default: return QObject::qt_emit(_id,_o); } return TRUE; }
// 连接按钮 void MainWindow::on_connectButton_clicked() { ui->fileList->clear(); currentPath.clear(); isDirectory.clear(); ftp = new QFtp(this); connect(ftp, SIGNAL(commandStarted(int)), this, SLOT(ftpCommandStarted(int))); connect(ftp, SIGNAL(commandFinished(int, bool)), this, SLOT(ftpCommandFinished(int, bool))); connect(ftp, SIGNAL(listInfo(QUrlInfo)), this, SLOT(addToList(QUrlInfo))); connect(ftp, SIGNAL(dataTransferProgress(qint64, qint64)), this, SLOT(updateDataTransferProgress(qint64, qint64))); QString ftpServer = ui->ftpServerLineEdit->text(); QString userName = ui->userNameLineEdit->text(); QString passWord = ui->passWordLineEdit->text(); ftp->connectToHost(ftpServer, 21); ftp->login(userName, passWord); }
/*! \fn FormActualizacion::iniciar() Conecta las se?ales, inicia la comunicacion ftp y coloca el primer comando */ void FormActualizacion::iniciar() { _continuar_actualizando = true; ftp = new QFtp( this ); connect( ftp, SIGNAL( commandFinished( int, bool ) ), this, SLOT( terminado( int, bool ) ) ); //connect( ftp, SIGNAL( commandStarted( int ) ), this, SLOT( inicio( int ) ) ); connect( ftp, SIGNAL( stateChanged( int ) ), this, SLOT( cambioEstado( int ) ) ); connect( ftp, SIGNAL( dataTransferProgress( qint64 , qint64 ) ), this, SLOT( transferencia( qint64, qint64 ) ) ); //connect( ftp, SIGNAL( readyRead() ), this, SLOT( datosListos() ) ); //Inicio la verificacion ActIniciar->setEnabled( false ); ActDetener->setEnabled( true ); // Busco los datos desde el registro para el host y puerto QSettings *p = preferencias::getInstancia(); //QString host = p->value( "actualizaciones/host", "tranfuga.no-ip.org" ).toString(); QString host = p->value( "Preferencias/Actualizaciones/servidor", "trafu.no-ip.org" ).toString(); quint16 puerto = p->value( "Preferencias/Actualizaciones/puerto", 21 ).toInt(); ftp->connectToHost( host, puerto ); }
void FtpWindow::connectToFtp() { //![1] ftp = new QFtp(this); connect(ftp, SIGNAL(commandFinished(int,bool)), this, SLOT(ftpCommandFinished(int,bool))); connect(ftp, SIGNAL(listInfo(QUrlInfo)), this, SLOT(addToList(QUrlInfo))); connect(ftp, SIGNAL(dataTransferProgress(qint64,qint64)), this, SLOT(updateDataTransferProgress(qint64,qint64))); fileList->clear(); currentPath.clear(); isDirectory.clear(); //![1] //![2] QUrl url(ftpServerLineEdit->text()); if (!url.isValid() || url.scheme().toLower() != QLatin1String("ftp")) { ftp->connectToHost(ftpServerLineEdit->text(), 21); ftp->login(); } else { ftp->connectToHost(url.host(), url.port(21)); if (!url.userName().isEmpty()) ftp->login(QUrl::fromPercentEncoding(url.userName().toLatin1()), url.password()); else ftp->login(); if (!url.path().isEmpty()) ftp->cd(url.path()); } //![2] fileList->setEnabled(true); connectButton->setEnabled(false); connectButton->setText(tr("Disconnect")); statusLabel->setText(tr("Connecting to FTP server %1...") .arg(ftpServerLineEdit->text())); }
Transfer::Transfer(QWidget *parent) : QDialog(parent), ui(new Ui::Transfer) { ui->setupUi(this); connect(&ftp_,SIGNAL(commandFinished(int,bool)), this,SLOT(OnFtpCommandFinished(int,bool))); connect(&ftp_,SIGNAL(listInfo(const QUrlInfo&)), this,SLOT(OnListInfo(const QUrlInfo&))); connect(&ftp_,SIGNAL(dataTransferProgress(qint64,qint64)), this,SLOT(OnDataTransferProgress(qint64,qint64))); setWindowTitle(tr("PP´«ÊäÖÐ")); setWindowFlags(Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint); // this->setAutoFillBackground(false); // animation_ = new QPropertyAnimation(this,"pos"); // connect(animation_,SIGNAL(finished()), // this,SLOT(OnAnimationFinished())); connect(&hide_time_,SIGNAL(timeout()), this,SLOT(hide())); this->setObjectName("sld_rate"); ReSet(); redc_ = new RedC; redc_->Init(); connect(redc_,SIGNAL(TransferError(const QString&)), this,SLOT(OnDownLoadError(const QString&))); connect(redc_,SIGNAL(DataTransferProgress(qint64,qint64)), this,SLOT(OnDownLoadProgress(qint64,qint64))); connect(redc_,SIGNAL(DownLoadFinish(const QString&)), this,SLOT(OnDownLoadFinish(const QString&))); }
void Q3LocalFs::operationGet( Q3NetworkOperation *op ) { #ifdef QLOCALFS_DEBUG qDebug( "Q3LocalFs: operationGet" ); #endif op->setState( StInProgress ); QString from = Q3Url( op->arg( 0 ) ).path(); QFile f( from ); if ( !f.open( IO_ReadOnly ) ) { #ifdef QLOCALFS_DEBUG qDebug( "Q3LocalFs: could not open %s", from.latin1() ); #endif QString msg = tr( "Could not open\n%1" ).arg( from ); op->setState( StFailed ); op->setProtocolDetail( msg ); op->setErrorCode( (int)ErrGet ); emit finished( op ); return; } QByteArray s; emit dataTransferProgress( 0, f.size(), op ); if ( f.size() != 0 ) { int blockSize = calcBlockSize( f.size() ); if ( (int)f.size() < blockSize ) { s.resize( f.size() ); f.readBlock( s.data(), f.size() ); emit data( s, op ); emit dataTransferProgress( f.size(), f.size(), op ); #ifdef QLOCALFS_DEBUG qDebug( "Q3LocalFs: got all %d bytes at once", f.size() ); #endif } else { s.resize( blockSize ); int remaining = f.size(); QPointer<QObject> that = this; while ( that && remaining > 0 ) { if ( operationInProgress() != op ) return; if ( remaining >= blockSize ) { f.readBlock( s.data(), blockSize ); emit data( s, op ); emit dataTransferProgress( f.size() - remaining, f.size(), op ); remaining -= blockSize; } else { s.resize( remaining ); f.readBlock( s.data(), remaining ); emit data( s, op ); emit dataTransferProgress( f.size() - remaining, f.size(), op ); remaining -= remaining; } qApp->processEvents(); } if ( !that ) return; #ifdef QLOCALFS_DEBUG qDebug( "Q3LocalFs: got all %d bytes step by step", f.size() ); #endif emit dataTransferProgress( f.size(), f.size(), op ); } } op->setState( StDone ); f.close(); emit finished( op ); }
} QxFtp::QxFtp(const QxFtp &) : QFtp(this) { } QxFtp::~QxFtp() { } void QxFtp::init_connects(){ connect(this, SIGNAL(stateChanged(int)), this, SLOT(old_stateChanged(int))); connect(this, SIGNAL(listInfo(const QUrlInfo&)), this, SLOT(old_listInfo(const QUrlInfo&))); connect(this, SIGNAL(readyRead()), this, SLOT(old_readyRead())); connect(this, SIGNAL(dataTransferProgress(qint64, qint64)), this, SLOT(old_dataTransferProgress(qint64, qint64))); connect(this, SIGNAL(rawCommandReply(int, const QString&)), this, SLOT(old_rawCommandReply(int, const QString&))); connect(this, SIGNAL(commandStarted(int)), this, SLOT(old_commandStarted(int))); connect(this, SIGNAL(commandFinished(int, bool)), this, SLOT(old_commandFinished(int, bool))); connect(this, SIGNAL(done(bool)), this, SLOT(old_done(bool))); } void QxFtp::old_stateChanged(int a) { emit x_stateChanged(this, a); } void QxFtp::old_listInfo(const QUrlInfo& a){ emit x_listInfo(this, a); } void QxFtp::old_readyRead(){ emit x_readyRead(this); }