void FtpWindow::upload_slot(){
QString name
= homefileList
->currentItem
()->text
(0);
// Here i get dir name from the treewidgetlist selected item
QString filepath
= path.
absoluteFilePath(name
);
// Since path is changed each time i click on a directory in treewidget and enter it, here is how i get the path of directory i want to upload
if (!isHomeDir.value(name)) {uploadFile(filepath, name);} // this is just checking if its dir or file
else { uploadDirectory(filepath, name); }
ftp->list();
}
void FtpWindow
::uploadFile(const QString
& filePath,
const QString &name
)
{
tr("Can't open file '%1' for reading.").arg(filePath) );
delete file;
return;
}
ftp->put(file, name);
}
void FtpWindow
::uploadDirectory(const QString
& dirPath,
const QString &name
)
{
uploadPath = currentPath;
qDebug() << uploadPath;
ftp->mkdir(name);
ftp->cd(name);
QDirIterator it(targetDir, QDirIterator::Subdirectories);
while (it.hasNext()) {
if(it.fileName() == "." | it.fileName() == ".." | it.fileName() == "/") continue;
if(info.isDir()) {
info.dir().absolutePath();
QString dirpath
= info.
absoluteFilePath().
remove(0, info.
absoluteFilePath().
indexOf('/'+ name
));
QString parentdir
= uploadPath
+ dirpath.
left(dirpath.
lastIndexOf('/'));
qDebug() << dirpath << "is dir and it's parent dir is " << parentdir ;
ftp->cd(parentdir);
ftp->mkdir(info.baseName());
}
else {
QString fajlovi
= info.
absoluteFilePath().
remove(0, info.
absoluteFilePath().
indexOf('/'+ name
));
QString parentdir
= uploadPath
+ fajlovi.
left(fajlovi.
lastIndexOf('/'));
// ftp->cd(parentdir);
qDebug() << fajlovi << "is file and its parent dir is " << parentdir ;
ftp->cd(parentdir);
uploadFile(info.absoluteFilePath(), info.baseName());
}
}
}
void FtpWindow::upload_slot(){
QString name = homefileList->currentItem()->text(0); // Here i get dir name from the treewidgetlist selected item
QString filepath = path.absoluteFilePath(name); // Since path is changed each time i click on a directory in treewidget and enter it, here is how i get the path of directory i want to upload
if (!isHomeDir.value(name)) {uploadFile(filepath, name);} // this is just checking if its dir or file
else { uploadDirectory(filepath, name); }
ftp->list();
}
void FtpWindow::uploadFile(const QString& filePath, const QString &name)
{
QFile *file = new QFile(filePath);
if ( !file->open(QIODevice::ReadOnly) ) {
QMessageBox::critical( this, tr("Upload error"),
tr("Can't open file '%1' for reading.").arg(filePath) );
delete file;
return;
}
ftp->put(file, name);
}
void FtpWindow::uploadDirectory(const QString& dirPath, const QString &name)
{
QDir targetDir(dirPath);
uploadPath = currentPath;
qDebug() << uploadPath;
ftp->mkdir(name);
ftp->cd(name);
QDirIterator it(targetDir, QDirIterator::Subdirectories);
while (it.hasNext()) {
QFileInfo info = it.next();
if(it.fileName() == "." | it.fileName() == ".." | it.fileName() == "/") continue;
if(info.isDir()) {
info.dir().absolutePath();
QString dirpath = info.absoluteFilePath().remove(0, info.absoluteFilePath().indexOf('/'+ name));
QString parentdir = uploadPath + dirpath.left(dirpath.lastIndexOf('/'));
qDebug() << dirpath << "is dir and it's parent dir is " << parentdir ;
ftp->cd(parentdir);
ftp->mkdir(info.baseName());
}
else {
QString fajlovi = info.absoluteFilePath().remove(0, info.absoluteFilePath().indexOf('/'+ name));
QString parentdir = uploadPath + fajlovi.left(fajlovi.lastIndexOf('/'));
// ftp->cd(parentdir);
qDebug() << fajlovi << "is file and its parent dir is " << parentdir ;
ftp->cd(parentdir);
uploadFile(info.absoluteFilePath(), info.baseName());
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks