[Qt-interest] QFtp broken during uploading

ammo ammonite99 at googlemail.com
Thu Nov 3 14:49:06 CET 2011


Hi all,
I've got a problem with QFtp. I'm trying to upload a large file
(approximately 130 MB) to a ftp-server. but the connection was always
broken during the uploading. I cannot find any errors in my code as
follows:

Test::Test(QWidget *parent) : QDialog(parent)
{
	ftp = 0;
	file = 0;
	connect_btn = new QPushButton(tr("connect"));
	disconn_btn = new QPushButton(tr("disconnect"));
	upload_btn = new QPushButton(tr("upload"));


	QHBoxLayout* layout = new QHBoxLayout;
	layout->addWidget(connect_btn);
	layout->addWidget(upload_btn);
	layout->addWidget(disconn_btn);
	this->setLayout(layout);
	connect(connect_btn, SIGNAL(clicked()), this, SLOT(on_connect()));
	connect(disconn_btn, SIGNAL(clicked()), this, SLOT(on_disconn()));
	connect(upload_btn, SIGNAL(clicked()), this, SLOT(on_upload()));
}

void Test::on_upload()
{
	QString name = "test";
	file = new QFile("C:\\Aurora\\ftp\bigdatamsi");
    if (!file->open(QIODevice::ReadOnly)) {
        delete file;
        return;
    }
	ftp->put(file, name);
	//file->deleteLater();
}

void Test::on_connect()
{
	QUrl url(tr("FTP://ftp-softzoll2:Q+683bjM@212.21.72.227:21/ftp-softzoll2"));
    if (ftp) {
        ftp->abort();
        ftp->deleteLater();
		ftp = 0;
	}
	ftp = new QFtp(this);
    connect(ftp, SIGNAL(commandFinished(int, bool)),
            this, SLOT(cmd_finished(int, bool)));
    connect(ftp, SIGNAL(dataTransferProgress(qint64,qint64)),
            this, SLOT(data_progress(qint64, qint64)));
	connect(ftp, SIGNAL(stateChanged(int)),
            this, SLOT(state_changed(int)));

	ftp->connectToHost(url.host(), url.port());
	ftp->login(QUrl::fromPercentEncoding(url.userName().toLatin1()),
url.password());
	ftp->cd(url.path());
}

void Test::on_disconn()
{
	if (ftp) {
		ftp->abort();
		ftp->close();
        ftp->deleteLater();
		ftp = 0;
	}
}



void Test::state_changed(int state)
{
	qDebug() << state;
}


void Test::cmd_finished(int, bool done)
{
	qDebug() << "cmd" << ftp->currentCommand() << "finished" << done;
	if (ftp && (ftp->currentCommand() == QFtp::Put)) {
		if (file) {
			file->close();
			delete file; file = 0;
		}
	}
}

void Test::data_progress(qint64 done, qint64 total)
{
	printf( "\r processed: [%5.4f]", (float)done/total);
}

this is a quite simple program, could anyone help me to find out where
the things goes wrong? thinks!

Henning



More information about the Qt-interest-old mailing list