Exemplo n.º 1
0
bool FtpCmdList :: endFtpCmd()
{
   // emit mes("end list ");
    //emit mes(QVariant(listF->size()).toString());
    disconnect(ftpconn,SIGNAL(listInfo(QUrlInfo)),this, SLOT(ftpList(QUrlInfo)));
    return true;
}
Exemplo n.º 2
0
bool	Ftp::Connect(const QString &urlpath, int timeout)
{
	connected = false;
	// if connectEnabled...
	currentHost = urlpath;
	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(stateChanged(int)), this, SLOT(ftpStateChanged(int)));
	//connect(ftp, SIGNAL(commandStarted(int)), this, SLOT(ftpCommandStarted(int)));
	//connect(ftp, SIGNAL(done(int)), this, SLOT(ftpDone(int)));
	fileList.clear();
	currentPath.clear();
	QUrl url(urlpath);
	if (!url.isValid() || url.scheme().toLower() != QLatin1String("ftp")) {
		qDebug() << "FTP: Connecting to " << urlpath;
		ftp->connectToHost(urlpath, 21);
		qDebug() << "FTP: Logging...";
		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());
	}
	// wait
	for (int i = 0; (i < timeout*10) || (!connected); i++)
		QTest::qWait(100);
	return connected;
}
Exemplo n.º 3
0
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();
}
Exemplo n.º 4
0
// Connection with the FTP Server. We retrieve the file list.
void CFtpSelection::ConnectButtonClicked()
{
	conn = new QFtp(this);
	connect(conn, SIGNAL(commandFinished(int,bool)), this, SLOT(FtpCommandFinished(int,bool)));
	connect(conn, SIGNAL(listInfo(QUrlInfo)), this, SLOT(AddToList(QUrlInfo)));

	setCursor(Qt::WaitCursor);

	QUrl url(_ui.url->text());
	if (!url.isValid() || url.scheme().toLower() != QLatin1String("ftp"))
	{
		conn->connectToHost(_ui.url->text(), 21);
		conn->login();
	}
	else
	{
		conn->connectToHost(url.host(), url.port(21));

		if (!url.userName().isEmpty())
			conn->login(QUrl::fromPercentEncoding(url.userName().toLatin1()), url.password());
		else
			conn->login();
		if (!url.path().isEmpty())
			conn->cd(url.path());
	}
}
Exemplo n.º 5
0
//![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()));
}
Exemplo n.º 6
0
void atWrapper::downloadBaseline()
{

    qDebug() << "Now downloading baseline...";

    QFtp ftp;

    QObject::connect( &ftp, SIGNAL(listInfo(QUrlInfo)), this, SLOT(ftpMgetAddToList(QUrlInfo)) );

    //Making sure that the needed local directories exist.

    QHashIterator<QString, QString> j(enginesToTest);

    while ( j.hasNext() )
    {
        j.next();

        QDir dir( output );

        if ( !dir.cd( j.key() + ".baseline" ) )
            dir.mkdir( j.key() + ".baseline" );

    }

    //FTP to the host specified in the config file, and retrieve the test result baseline.
    ftp.connectToHost( ftpHost );
    ftp.login( ftpUser, ftpPass );

    ftp.cd( ftpBaseDir );

    QHashIterator<QString, QString> i(enginesToTest);
    while ( i.hasNext() )
    {
        i.next();
        mgetDirList.clear();
        mgetDirList << i.key() + ".baseline";
        ftp.cd( i.key() + ".baseline" );
        ftp.list();
        ftp.cd( ".." );

        while ( ftp.hasPendingCommands() )
            QCoreApplication::instance()->processEvents();

        ftpMgetDone( true );
    }

    ftp.close();
    ftp.close();

    while ( ftp.hasPendingCommands() )
        QCoreApplication::instance()->processEvents();

}
Exemplo n.º 7
0
int main (void)
{
phoneInfo *head = NULL;
char key = 0;
#define kEnter    '1'
#define kList     '2'
#define kDelete   '3'
#define kQuit     '4'
#define kLoopForever   1 

	// loop getting user input until they indicate that they want to quit
	while( kLoopForever ) 
	{
		// display menu and get input

		printf("\n\nMenu\n\n");
		printf("%c . . . Enter new info\n", kEnter);
		printf("%c . . . List all info\n", kList);
		printf("%c . . . Delete all info\n", kDelete);
		printf("%c . . . Quit\n", kQuit);
		printf("Enter your choice . . .");

		key = getch();

		// quit on entry of kQuit ('4')
		if( key == kQuit )
		{
			break;
		}

		switch( key ) 
		{
		case kEnter:
			head = enterNewInfo(head);
			break;

		case kList:
			listInfo(head);
			break;

		case kDelete:
			head = deleteAllInfo(head);
			break;

		default:
			printf("\nInvalid choice\n");
			break;
		}	/* end switch */
	}	/* end while */

	return 0;
}	/* end main() */
Exemplo n.º 8
0
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()));
}
Exemplo n.º 9
0
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);
}
Exemplo n.º 10
0
//! [constructor]
FtpReply::FtpReply(const QUrl &url)
    : QNetworkReply()
{
    ftp = new QFtp(this);
    connect(ftp, SIGNAL(listInfo(QUrlInfo)), this, SLOT(processListInfo(QUrlInfo)));
    connect(ftp, SIGNAL(readyRead()), this, SLOT(processData()));
    connect(ftp, SIGNAL(commandFinished(int, bool)), this, SLOT(processCommand(int, bool)));

    offset = 0;
    units = QStringList() << tr("bytes") << tr("K") << tr("M") << tr("G")
                          << tr("Ti") << tr("Pi") << tr("Ei") << tr("Zi")
                          << tr("Yi");

    setUrl(url);
    ftp->connectToHost(url.host());
}
Exemplo n.º 11
0
// 连接按钮
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);
}
Exemplo n.º 12
0
void atWrapper::ftpRmDir( QString dir )
{
    //Hack to remove a populated directory. (caveat: containing only files and empty dirs, not recursive!)
    qDebug() << "Now removing directory: " << dir;
    QFtp ftp;
    QObject::connect( &ftp, SIGNAL(listInfo(QUrlInfo)), this, SLOT(ftpRmDirAddToList(QUrlInfo)) );
    QObject::connect( &ftp, SIGNAL(done(bool)), this, SLOT(ftpRmDirDone(bool)) );

    ftp.connectToHost( ftpHost );
    ftp.login( ftpUser, ftpPass );

    ftp.list( ftpBaseDir + "/" +  dir );
    ftp.close();
    ftp.close();

    while ( ftp.hasPendingCommands() )
                QCoreApplication::instance()->processEvents();
}
Exemplo n.º 13
0
void ftpClient::connectOrDisconnect()
{
    if (ftp) {
        ftp->abort();
        ftp->deleteLater();
        ftp = 0;
//![0]
        qDebug()<<"Connect";
        qDebug()<<"Please enter the name of an FTP server.";
        return;
    }

//![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)));

//![1]

//![2]

    QUrl url(ftpServer);
    if (!url.isValid() || url.scheme().toLower() != QLatin1String("ftp")) {
        ftp->connectToHost(ftpServer, 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]
    qDebug()<<(tr("Disconnect"));
    qDebug()<<(tr("Connecting to FTP server %1...").arg(ftpServer));
}
Exemplo n.º 14
0
bool FtpCmdList :: doFtpCmd()
{
    if(listF==0)
    {
        lastErr.redefine("List of files id NULL.");
        return false;
    }
    listF->clear();
/*    if(not ftpName.isValid())
    {
        lastErr.redefine("FTP catalog name is not valid");
        return false;
    }
    //emit mes(ftpName.getFullName());
*/
    if( QMetaType::type("QUrlInfo") == 0)
        qRegisterMetaType<QUrlInfo>("QUrlInfo");
    connect(ftpconn,SIGNAL(listInfo(QUrlInfo)),this,SLOT(ftpList(QUrlInfo)));
    ftpconn->list(ftpName.getFullName());
    return true;
}
Exemplo n.º 15
0
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());
    }


}
Exemplo n.º 16
0
void FtpApp::getFiles()
{
    Qt::Alignment leftBottom = Qt::AlignLeft | Qt::AlignBottom;

    splash->showMessage("Looking up host...",leftBottom,Qt::white);
    statusLabel->setText("Looking up host...");
    ftp = new QFtp(this);
    fileList->clear();

    connect(ftp, SIGNAL(listInfo(QUrlInfo)),
                this, SLOT(addToList(QUrlInfo)));
    connect(ftp,SIGNAL(stateChanged(int)),this,SLOT(changeOfState(int)));

    QUrl url("ftp://ftp.ftpjigs.comze.com/public_html/");
    url.setPort(21);
    url.setUserName("a1996228");
    url.setPassword("11107jigs");
    std::cout<<qPrintable(url.path())<<"\n";
    ftp->connectToHost(url.host(),url.port(21));
    ftp->login(url.userName(),url.password());
}
Exemplo n.º 17
0
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()));
}
Exemplo n.º 18
0
void Fritzbox::finishFtpJob(int id, bool errorId) {
		if (lastFtpJob.first != id) return;

		switch (lastFtpJob.second) {

			case FTPconnect:
				if (errorId) {
					emit error("Authentifizierung fehlgeschlagen.");
					break;
				}
				// set default dir
				lastFtpJob.first = ftp.list("/");
				lastFtpJob.second = FTPdefaultDir;
				connect(&ftp, SIGNAL(listInfo(QUrlInfo)), this, SLOT(finishFtpList(QUrlInfo)));
				break;

			case FTPenterVoicebox:
				if (errorId) {
					emit error("Die vorliegende Dateistruktur entspricht nicht der einer Fritzbox.");
					break;
				}
				lastFtpJob.first = ftp.cd("announcements");
				lastFtpJob.second = FTPcheckAnnouncementsDir;
				break;

			case FTPcheckAnnouncementsDir:
				if (errorId) {
					ftp.mkdir("announcements");
				}
				lastFtpJob.first = ftp.get(getXMLfilename());
				lastFtpJob.second = FTPloadAnnouncementsXML;
				break;

			case FTPloadAnnouncementsXML: {
				if (!errorId) {
					QDomDocument announcementsXML;
					announcementsXML.setContent(ftp.readAll());
					QDomNodeList announcementList = announcementsXML.elementsByTagName("item");
					for (int i = 0; i < announcementList.size(); i++) {
						QDomNode announcement = announcementList.at(i);
						announcements.push_back(pair<QString, QString>(announcement.firstChildElement("hash").text(), announcement.firstChildElement("name").text()));
					}
				}
				ftp.cd("..");
				updateCurAnnouncementHash();
				break;
			}

			case FTPupdateHash: {
				if (errorId) {
					if (++tamType > 2) {
						emit error("Es wurde keine aufgezeichnete Ansage gefunden.");
					} else {
						updateCurAnnouncementHash();
					}
					break;
				}
				QByteArray data(ftp.readAll());
				curAnnouncementHash = QCryptographicHash::hash(data, QCryptographicHash::Md5).toHex().constData();
				emit updatedAnnouncement();

				if (!ftpFinished) {
					ftpFinished = true;
					finishGlobalJob();
				}
				break;
			}

			case FTPgetNew: {
				QByteArray data(ftp.readAll());
				ftp.cd("announcements");
				lastFtpJob.first = ftp.put(data, curAnnouncementHash);
				lastFtpJob.second = FTPsaveNew;
				break;
			}

			case FTPsaveNew:
				if (errorId) {
					emit error("Konnte Ansage nicht speichern.");
					announcements.pop_back();
				} else {
					saveXMLfile();
				}
				emit savedNewAnnouncement();
				break;

			case FTPloadAnnouncement: {
				QByteArray data(ftp.readAll());
				ftp.cd("..");
				deleteCurAnnouncement();
				lastFtpJob.first = ftp.put(data, getCurAnnouncementFilename());
				lastFtpJob.second = FTPsaveAnnouncement;
				break;
			}

			case FTPsaveAnnouncement:
				emit updatedAnnouncement();
				emit finishedJob();
				break;

			case FTPsaveAnnouncementsXML:
				ftp.cd("..");
				break;

			default:
				break;

		}

}