Read this thread and didn't see anything useful. The problem seems non-trivial, yet the responses suggest it's only difficult if you don't understand ftp. I disagree!
My situation is similar, except I want to do an ftp of a file and create a directory structure on the remote host based on a part of the local file's path. Which means I need to ftp->mkdir to create directories as needed before doing the ftp->put().
For example, I have a file named /la/lb/d/e/f/file.jpg. I want it to end up on the ftp server in something like /ftptop/d/e/f/file.jpg
So, there needs to be a sequence of ftp->mkdir, ftp->cd commands to create the directory structure on the remote host before doing the final ftp->put.
Something like this doesn't work:
qDebug()<< dirs2Make;
{
qDebug() << "making directory " << d;
ftp->mkdir(d);
ftp->cd(d);
}
ftp->put ftpFile;
QStringList dirs2Make = ftpDir.split("/");
qDebug()<< dirs2Make;
foreach (QString d,dirs2Make)
{
qDebug() << "making directory " << d;
ftp->mkdir(d);
ftp->cd(d);
}
ftp->put ftpFile;
To copy to clipboard, switch view to plain text mode
Because if directories already exist in the remote path, the sequence will terminate. So, if a directory exists, cd into it. If not mkdir first, then cd into. Sounds simple, but it's not that easy.
The QFtp commands are asynchronous. Which means you have to schedule a sequence and wait for it to complete or for a command in the sequence to fail. Then create another sequence based on if and how the prior scheduled sequence completed.
Figuring out which command in a sequence failed requires keeping an association of a sequence number to the each of the commands in the sequence.
So, unless I'm missing something, there's more too it than just understanding how ftp works. I'm thinking it would be easier to just shell out to a script that does the ftp commands--that way the ftp commands can more easily be dynamically created based on the pass/fail result of a prior command.
Basically, what I'd need is a way to do everything but the actual put synchronously. Commands like login, cd, mkdir typically complete quickly and often alter what should happen next based on whether they pass or fail.
Bookmarks