Only one file going up in my Ftp site when uploading with QFtp
-
I have a unexpected problem when uploading files using QFtp to my ftp site. If I empty the directory of stuff on my ftp site and upload a file, it shows up just as expected. But when I attempt to send a second file it appears to upload, but nothing appears in the directory!
If I delete the first file from the ftp site and send the second file (without shutting down my code, mind you), the second file will go up. But now the first file won't go up. Its as thought I'm only allowed one file in the directory.
Here's the code I am using to upload a file to my site:
@void NetworkManager::uploadLocalToFtp( const QString &_localpath, const QString &_ftppath )
{
if( m_ftp ) {
deleteFile();
m_file = new QFile(_localpath);
if(!m_file->open(QIODevice::ReadOnly))
{
QString errmsg = QString("Unable to upload file %1: %2").arg(_localpath).arg(m_file->errorString());
logError(errmsg);
deleteFile();
setAbort(true);
} else {
m_ftp->put(m_file, _ftppath);
logNote("Uploading " + _localpath);
}
} else
logError("You must be logged into the ftp site first.");
}@When the upload is completed, a commandFinished() signal is issued. This is my code for that:
@void NetworkManager::ftpCommandFinished( int _v, bool _error)
{
if( m_ftp )
{
if( m_ftp->currentCommand() == QFtp::Get)
{
if( _error ) {
logError("Cancelled download. " + m_file->fileName());
m_file->close();
m_file->remove();
} else {
logNote("Downloaded file " + m_file->fileName());
m_file->close();
}
deleteFile();
} else if( m_ftp->currentCommand() == QFtp::Put)
{
if( _error ) {
logError("Cancelled upload. " + m_file->fileName());
m_file->close();
m_file->remove();
} else {
logNote("Uploaded file " + m_file->fileName());
m_file->close();
}
deleteFile();
}
}
}@ -
Did you try taking Qt out of it and just using a command line ftp to put the multiple files. That will make sure your ftp stuff on your server is functioning properly.
As for the Qt issue, is _ftppath changing at all? Is it the same for each call? Can you qDebug() or trace that in a log file or debugger to make sure.
Also, another problem I see is in your ftpCommandFinished() why would you m_file->remove() the local file if an upload fails. I could see that for a download but an upload that would be bad to remove the user's file. I imagine that is a copy/paste oversight.
And then finally, what does the deleteFile() call do at the end of ftpCommandFinished()?
-
I spoke hastily. I was going off what I was seeing in Mozilla. I can upload the files and it seems to only want to update the directory sporadically. I found when I queried the ftp site with my code, it saw the two files. I logged off of Mozilla and re-logged in and there were the two files. I do wonder if I am properly "closing up" the put however.
If someone with some experience could look over my code for anything obviously wrong, I would appreciate it!
Thanks in advance.
-
I'm glad you spotted that m_file->remove(). I copied he get code into the put code. and this would explain why my source file turned into junk!
As far as the deleteFile() function, this is it:
@void NetworkManager::deleteFile()
{
if( m_file )
delete m_file;
m_file = NULL;
}@ -
So if you refresh the browser page after you ftp the file it doesn't show up? You can always try the command line:
ftp myserver.com
(login)
cd /your/directory
lsThat should show you the file list. Then put the files, and "ls" again. If it doesn't show both of them something is weird/wrong.
It's not surprising that mozilla isn't catching the changes. Browsers like to cache things. If refreshing doesn't work then it's a caching issue more than likely.
-
Ah ok deleteFile() isn't affecting anything since it's just memory cleanup.
-
Hey thanks for your help. Appears to be working now.