[Qt-interest] FTP : File upload
amulya rattan
talk2amulya at gmail.com
Thu Mar 25 08:32:19 CET 2010
Guys,
I am trying to upload a file to the server. On command finished, no error is
returned however I dont see the file uploaded on the ftp site.
Do I have to add extra measure to have the file saved on the site?
Here is the code for anyone interested:
void PostCrashSummary::startUploading()
{
_ftp = new QFtp(this);
connect(_ftp, SIGNAL(commandFinished(int,bool)),
this, SLOT(ftpCommandFinished(int,bool)));
connect(_ftp, SIGNAL(dataTransferProgress(qint64,qint64)),
this, SLOT(updateDataTransferProgress(qint64,qint64)));
bool ret = connect(_ftp, SIGNAL(stateChanged(int)),
this, SLOT(onStateChanged(int)));
QUrl url(FtpUrl);
if (!url.isValid() || url.scheme().toLower() != QLatin1String("ftp")) {
_ftp->connectToHost(FtpUrl, 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();
}
//QString fileOnPBServer = "stackTrace_" +
QDateTime::currentDateTime().toString() + ".txt";
QString fileOnPBServer = "st.txt";
_file = new QFile(FileLocation);
_file->open(QIODevice::ReadOnly);
QByteArray data = _file->readAll();
_ftp->put(data, fileOnPBServer, QFtp::Ascii);
}
void PostCrashSummary::updateDataTransferProgress(qint64 readBytes,
qint64 totalBytes)
{
ui.progressBar->setMaximum(totalBytes);
ui.progressBar->setValue(readBytes);
}
void PostCrashSummary::ftpCommandFinished(int command, bool error)
{
if (_ftp->currentCommand() == QFtp::Put)
{
if (error)
{
QMessageBox::information(NULL, "File Transfer", _ftp->errorString());
}
else
{
QMessageBox::information(NULL, "File Transfer", "Successfully transferred");
}
_file->close();
delete _file;
_file = NULL;
_ftp->close();
_ftp->deleteLater();
_ftp = NULL;
qApp->quit();
}
}
Any pointers are appreciated!
Thanks,
~Amulya
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100325/e8dfbb89/attachment.html
More information about the Qt-interest-old
mailing list