[Qt-interest] FTP : File upload
Ulf-Alexander v. Ceumern-Lindenstjerna
ceumern at vrmagic.com
Thu Mar 25 10:45:10 CET 2010
Hi,
from what I see your code looks fine. You do not have to take extra
measure to have the file saved on the site. Make sure the user used for
upload has the correct rights on the ftp server, such as put, list, etc.
Check the log of the ftp server to try to find out what really happens
on the server side.
Hth, Ulf
> -----Original Message-----
> From: qt-interest-bounces at trolltech.com [mailto:qt-interest-
> bounces at trolltech.com] On Behalf Of amulya rattan
> Sent: Thursday, March 25, 2010 8:32 AM
> To: qt-interest at trolltech.com
> Subject: [Qt-interest] FTP : File upload
>
> 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
More information about the Qt-interest-old
mailing list