PDA

View Full Version : QFtp bug ?? When in active mode



fredcrs
25th May 2010, 13:20
SO I´m into some problems, because my application is ready and the ftp part is not working very well as I had to change the Ftp Client (QFtp) to active mode, due to firewall into the network here.

So the Ftp protocol should work like this for uploading a file: It is the resume of the packets captured from a working ftp Client

Client Server
PORT command from myPort --> destination port 21
to myPort <-- PORT Command sucessfull.
STOR fileName.ext --> destination port 21
to myPort <-- Opening mode data connection for fileName.ext
to port PORT <-- from port 20 (SYN) *TCP PROTOCOL
from port PORT --> to port 20 (SYN, ACK) *TCP PROTOCOL
to port PORT <-- from port 20 (ACK) *TCP PROTOCOL
from port PORT DATA --> DATA to port 20




So here is what is happening with my QFtp application using Active mode:

Client [i[Server[/i]
PORT command from myPort --> destination port 21
to myPort <-- PORT Command sucessfull.
ALLO command from myPort --> destination port 21
to myPort <-- ALLO Command sucessfull.
STOR fileName.ext --> destination port 21
to myPort <-- Opening mode data connection for fileName.ext
to port PORT <-- from port 20 (SYN) *TCP PROTOCOL
from port PORT --> to port 20 (SYN, ACK) *TCP PROTOCOL
to port PORT <-- from port 20 (ACK) *TCP PROTOCOL
from myPort --> to port 21 (ACK) *TCP Protocol
----------- NO MORE CONVERSATION-----------------------


on both transfers I got TYPE SET TO I ok....
Also, when listing the files it does work perfectly....

The server type is, from WS_FTP
SYST
215 Windows_NT
Host type (2): Microsoft NT

But the error also happens in other servers, but not always

It does create the file on the server, but it has 0 bytes!
No, its not permission problem...it worked OK with all other Ftp clients

I hope someone here can help me...I´m stuck on this for some weeks...
Cheers


Oh, this is the code I use to upload the files...

#include "FtpFileSender.h"

FtpFileSender::FtpFileSender(QFtp *ftp) : nomeArquivoEnviando(NULL), barraDeProgresso(NULL)
{
this->ftp = ftp;
connect(ftp, SIGNAL(commandFinished(int, bool)), this, SLOT(comandoFinalizado(int, bool)));
}

void FtpFileSender::enviarArquivos(QStringList caminhoArquivos) throw (QString*)
{
arquivosErro.clear();
mapaDeArquivos.clear();
QString nome;
QFile *file = NULL;
for(int i=0; i<caminhoArquivos.size(); i++)
{
file = new QFile(caminhoArquivos.at(i));
file->open(QIODevice::ReadOnly);
nome = this->getNomeArquivo(file->fileName());
mapaDeArquivos.insert(ftp->put(file, nome, QFtp::Binary), file);
}
}

QString FtpFileSender::getNomeArquivo(QString caminhoArquivo)
{
QString nome;
QStringList nomeAux;
nome = caminhoArquivo;
if(nome.contains("/"))
{
nomeAux = nome.split("/");
nome = nomeAux.at(nomeAux.size()-1);
}
else if(nome.contains("\\"))
{
nomeAux = nome.split("\\");
nome = nomeAux.at(nomeAux.size()-1);
}
return nome;
}

void FtpFileSender::comandoFinalizado(int id, bool erro)
{
if(!this->mapaDeArquivos.contains(id))
return;
QFile* arquivo = mapaDeArquivos.take(id);
if(erro)
arquivosErro.append(arquivo->fileName());
arquivo->close();
delete arquivo;
if(mapaDeArquivos.empty())
{
emit(fim(arquivosErro));
}
}

void FtpFileSender::setLabelArquivoSendoEnviado(QLabel* label)
{
this->nomeArquivoEnviando = label;
connect(ftp, SIGNAL(commandStarted(int)), this, SLOT(comandoIniciado(int)));
}

void FtpFileSender::unsetLabelArquivoSendoEnviado()
{
disconnect(ftp, SIGNAL(commandStarted(int)), this, SLOT(comandoIniciado(int)));
this->nomeArquivoEnviando = NULL;
}



void FtpFileSender::unsetProgressBar()
{
disconnect(ftp, SIGNAL(dataTransferProgress(qint64, qint64)), barraDeProgresso, SLOT(setDataTransferProgress(qint64, qint64)));
this->barraDeProgresso = NULL;
}


void FtpFileSender::comandoIniciado(int id)
{
if(this->nomeArquivoEnviando == NULL)
return;
if(!this->mapaDeArquivos.contains(id))
return;
QString nome(this->mapaDeArquivos.value(id)->fileName());
this->nomeArquivoEnviando->setText(this->getNomeArquivo(nome));
}

void FtpFileSender::setProgressBar(BarraDeProgresso* barra)
{
this->barraDeProgresso = barra;
connect(ftp, SIGNAL(dataTransferProgress(qint64, qint64)), barraDeProgresso, SLOT(setDataTransferProgress(qint64, qint64)));
}


FtpFileSender::~FtpFileSender()
{

}

fredcrs
25th May 2010, 14:34
Oh well,
using Java and apache commons net it worked OK, so I think its a BUG from QFtp.... How can I report it?