smshamim
30th August 2006, 13:37
Hi all,
Here is my problem:
Purpose:- Upload a directory from local host to remote machine (remote ftp server)
Qt Class in use:- QFtp Class
Problem:-
Source code given below, works fine if I put QmessageBox after line:
ftp->mkdir(directoryName);
Otherwise I get the error-
Changing directory failed:
Failed to change directory.
Source Code:-
uploadDirectory(QDir dir){
QString absPath=dir.absPath();
QString directoryName=absPath.section('/',-1);
dir.setSorting(QDir::DirsFirst);
const QFileInfoList *localFileInfoList = dir.entryInfoList();
QFileInfoListIterator fileIterator(*localFileInfoList );
int count=localFileInfoList->count();
QFileInfo* file;
int mkdirFlag =1;
for(int temp=0;temp<count;temp++) {
file=fileIterator.current();
if(mkdirFlag){
ftp->rawCommand( "PWD" );
ftp->mkdir(directoryName);
mkdirFlag=0;
currentDir->cd(directoryName);
QString ftpString=ftpDir+QString("/")+directoryName;
ftp->cd(ftpString);
}
if(file->isDir() && file->fileName()!="." && file->fileName()!=".."){
uploadDirectory(QDir(currentDir->absPath()+QString("/")+QString(file->fileName())));
}
if(!file->isDir())
uploadFile(currentDir->absPath()+QString("/")+file->fileName());
++fileIterator;
}
ftp->cd("..");
currentDir->cdUp();
}
Description:-
ftp:-denotes the remote ftp(Class QFtp)
currentDir:-denotes the current local directory(QDir)
ftpDir:-denotes current remote file path (QString)
Note: - we get this value by sending PWD command( ftp->rawCommand( "PWD") ) in the command reply function we set this value in ftpDir
directoryName:- if dir is “home/username/folder1†then directoryName gives folder1
uploadFile() function uploads the given file
Observation:-
It takes time to complete the function like get, put, mkdir, cd etc. and these functions are nonblocking. Program doesn’t block here. Just take an example if I call ‘mkdir’ (ftp->mkdir()) then program doesn’t wait for completion of this function. It goes to next line and performs (ftp->cd()) and I get the error.
How should I resolve this problem?
Thanks :)
Here is my problem:
Purpose:- Upload a directory from local host to remote machine (remote ftp server)
Qt Class in use:- QFtp Class
Problem:-
Source code given below, works fine if I put QmessageBox after line:
ftp->mkdir(directoryName);
Otherwise I get the error-
Changing directory failed:
Failed to change directory.
Source Code:-
uploadDirectory(QDir dir){
QString absPath=dir.absPath();
QString directoryName=absPath.section('/',-1);
dir.setSorting(QDir::DirsFirst);
const QFileInfoList *localFileInfoList = dir.entryInfoList();
QFileInfoListIterator fileIterator(*localFileInfoList );
int count=localFileInfoList->count();
QFileInfo* file;
int mkdirFlag =1;
for(int temp=0;temp<count;temp++) {
file=fileIterator.current();
if(mkdirFlag){
ftp->rawCommand( "PWD" );
ftp->mkdir(directoryName);
mkdirFlag=0;
currentDir->cd(directoryName);
QString ftpString=ftpDir+QString("/")+directoryName;
ftp->cd(ftpString);
}
if(file->isDir() && file->fileName()!="." && file->fileName()!=".."){
uploadDirectory(QDir(currentDir->absPath()+QString("/")+QString(file->fileName())));
}
if(!file->isDir())
uploadFile(currentDir->absPath()+QString("/")+file->fileName());
++fileIterator;
}
ftp->cd("..");
currentDir->cdUp();
}
Description:-
ftp:-denotes the remote ftp(Class QFtp)
currentDir:-denotes the current local directory(QDir)
ftpDir:-denotes current remote file path (QString)
Note: - we get this value by sending PWD command( ftp->rawCommand( "PWD") ) in the command reply function we set this value in ftpDir
directoryName:- if dir is “home/username/folder1†then directoryName gives folder1
uploadFile() function uploads the given file
Observation:-
It takes time to complete the function like get, put, mkdir, cd etc. and these functions are nonblocking. Program doesn’t block here. Just take an example if I call ‘mkdir’ (ftp->mkdir()) then program doesn’t wait for completion of this function. It goes to next line and performs (ftp->cd()) and I get the error.
How should I resolve this problem?
Thanks :)