{
QDir localDir
(localPath
);
listCommandVector.append(ftp->list(path));
stack.push(path);
localDir.mkdir(path);
connect(ftp,SIGNAL(commandFinished(int,bool)),this,SLOT(processCommand(int,bool)));
lpath=localPath;
}
void qOrganizer
::processFolder(const QUrlInfo &i
) {
if(i.isDir())
{
entryList.push_front(i);
}
else
if(i.isFile())
entryList.push_back(i);
}
static int nrcomfin=0;
void qOrganizer::processCommand(int com,bool err)
{
nrcomfin++;
bool containsSubfolders=0;
bool entryExists=0;
if(listCommandVector.indexOf(com)!=-1)
{
path = stack.top();
{
if((entry.isFile())&&(listedFiles.indexOf(entry)==-1))
{
QString foldPath
= path
+"/"+entry.
name();
ftpEntryes->append(foldPath);
listedFiles.append(entry);
cout <<"File:"<<foldPath<<"\n";
entryExists=1;
}
else
if((entry.isDir())&&(listedFolders.indexOf(entry)==-1))
{
QString foldPath
= path
+"/"+entry.
name();
// cout <<"Folder:"<<foldPath<<"\n";
stack.push(foldPath);
localDir.mkdir(foldPath);
// cout << stack.top() <<"\n";
listCommandVector.append(ftp->list(foldPath));
listedFolders.append(entry);
containsSubfolders=1;
entryExists=1;
break;
}
}
if((stack.size()>1)&&(nrcomfin%2!=0)) stack.pop();
entryList.clear();
//cout << stack.size() << stack.top() <<" "<<nrcomfin<<"\n";
if((!containsSubfolders)&&(entryExists))
listCommandVector.append(ftp->list(stack.top()));
if((!containsSubfolders) && (!entryExists)) downloadFiles();
}
else
if(getCommandVector.indexOf(com)!=-1)
{
ftpFile=fileQueue.dequeue();
ftpFile-> close();
cout <<"Completed:"<<ftpFile->fileName()<<" "<<"Errors:"<<err<<"\n";
ftpFile->deleteLater();
};
}
void qOrganizer::downloadFiles()
{
cout <<"Downloading"<<"\n";
{
cout << "get " << entry <<" "<<lpath+entry<<"\n";
fileQueue.enqueue(file);
getCommandVector.append(ftp -> get(entry,file));
}
}
void qOrganizer::getFolder(QString path,QString localPath)
{
QTextStream cout(stdout, QIODevice::WriteOnly);
QDir localDir(localPath);
listCommandVector.append(ftp->list(path));
stack.push(path);
localDir.mkdir(path);
connect(ftp,SIGNAL(listInfo(QUrlInfo)),this,SLOT(processFolder(QUrlInfo)));
connect(ftp,SIGNAL(commandFinished(int,bool)),this,SLOT(processCommand(int,bool)));
ftpEntryes = new QStringList;
lpath=localPath;
}
void qOrganizer::processFolder(const QUrlInfo &i)
{
if(i.isDir())
{
entryList.push_front(i);
}
else
if(i.isFile())
entryList.push_back(i);
}
static int nrcomfin=0;
void qOrganizer::processCommand(int com,bool err)
{
nrcomfin++;
QString path;
QTextStream cout(stdout, QIODevice::WriteOnly);
bool containsSubfolders=0;
bool entryExists=0;
QDir localDir(lpath);
if(listCommandVector.indexOf(com)!=-1)
{
path = stack.top();
foreach(QUrlInfo entry,entryList)
{
if((entry.isFile())&&(listedFiles.indexOf(entry)==-1))
{
QString foldPath = path+"/"+entry.name();
ftpEntryes->append(foldPath);
listedFiles.append(entry);
cout <<"File:"<<foldPath<<"\n";
entryExists=1;
}
else
if((entry.isDir())&&(listedFolders.indexOf(entry)==-1))
{
QString foldPath = path+"/"+entry.name();
// cout <<"Folder:"<<foldPath<<"\n";
stack.push(foldPath);
localDir.mkdir(foldPath);
// cout << stack.top() <<"\n";
listCommandVector.append(ftp->list(foldPath));
listedFolders.append(entry);
containsSubfolders=1;
entryExists=1;
break;
}
}
if((stack.size()>1)&&(nrcomfin%2!=0)) stack.pop();
entryList.clear();
//cout << stack.size() << stack.top() <<" "<<nrcomfin<<"\n";
if((!containsSubfolders)&&(entryExists))
listCommandVector.append(ftp->list(stack.top()));
if((!containsSubfolders) && (!entryExists)) downloadFiles();
}
else
if(getCommandVector.indexOf(com)!=-1)
{
ftpFile=fileQueue.dequeue();
ftpFile-> close();
cout <<"Completed:"<<ftpFile->fileName()<<" "<<"Errors:"<<err<<"\n";
ftpFile->deleteLater();
};
}
void qOrganizer::downloadFiles()
{
QTextStream cout(stdout, QIODevice::WriteOnly);
cout <<"Downloading"<<"\n";
foreach(QString entry,*ftpEntryes)
{
QFile *file = new QFile(lpath+entry);
cout << "get " << entry <<" "<<lpath+entry<<"\n";
fileQueue.enqueue(file);
file->open(QIODevice::WriteOnly);
getCommandVector.append(ftp -> get(entry,file));
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks