PDA

View Full Version : problem with mkdir() in QFtp



fatima
14th July 2009, 09:35
Hi,

I have tried that QFtp example for making a ftp client. It works fine.
But I am unable to make any directory on the remote server using mkdir().

Please tell me how to do that.

Lykurg
14th July 2009, 10:08
What have you tried, how does your code look like and more important, have you the rights to create a folder at the ftp server?

fatima
20th July 2009, 08:22
Hi,
Thanx for replying.

I am making an application that needs to create a folder on the remote computer using ftp.

The code I am using is as below -
************************************************** ************************************************** ****
ftpSignupAddress = "ftp://172.17.70.99/pub/casestudy/";

wftp = new QFtp(this);
connect(wftp, SIGNAL(commandFinished(int, bool)),this,
SLOT(wftpCommandFinished(int, bool)));

QUrl wurl(ftpSignupAddress);
if (!wurl.isValid() || wurl.scheme().toLower() != QLatin1String("ftp")) {
wftp->connectToHost(ftpSignupAddress, 21);
wftp->login();
} else {
wftp->connectToHost(wurl.host(), wurl.port(21));

if (!wurl.userName().isEmpty())
{ wftp->login(QUrl::fromPercentEncoding(wurl.userName().to Latin1()), wurl.password());
}
else
{wftp->login();
}
if (!wurl.path().isEmpty())
{wftp->cd(wurl.path());
}
}

int b=wftp->rename("user1", "user5");
qDebug() << "rename : " << b ;
qDebug() << "rename : " << wurl.path() ;
int a = wftp->mkdir("user007");
qDebug() << "mkdir : " << a ;
}
}

************************************************** ************************************************** ****
On executing this code :

qDebug() << "rename : " << b ; ------> gives me an integer value = 4

qDebug() << "mkdir : " << a ; -----> gives me an integer value = 5

But still there is no folder renaming of the folder.
there is no folder named "user007" get created.

* for the permissions to the ftp server. I am using my own ftp to test this code. And I have given 777 permissions to my /var/ftp/pub folder.
the command i used is -
sudo chmod -R 777 /var/ftp/pub

Please tell me , what else I should do.

miwarre
20th July 2009, 23:35
Hi,
Thanx for replying.

I am making an application that needs to create a folder on the remote computer using ftp.

[...]

Please tell me , what else I should do.

Hi,

As you probably know, the QFtp command functions like rename() and mkdir() do nothing by themselves but enqueue that command for asynch execution. So, the int returned by, for instance, wftp->mkdir("user007"); is not a sucess/failure code but the index of that operation in the queue.

As the first lines in your code show, somewhere else in your code you need to define two private slots:


void wftpCommandFinished(int iCommand, bool bError);
void wftpDone(bool bError);

and connect them to QFtp signals:


connect(wftp, SIGNAL(commandFinished(int,bool)), this, SLOT(wftpCommandFinished(int,bool)));
connect(wftp, SIGNAL(done(bool)), this, SLOT(wftpDone(bool)));

In the wftpCommandFinished() slot code, you may test for error and, if any, get the code and the description of the error with wftp->error() and wftp->errorString(). This may cast more light on the reason of the failure. Same for wftpDone.

Ciao,

Miwarre