Russian Qt Forum
Март 29, 2024, 10:17 *
Добро пожаловать, Гость. Пожалуйста, войдите или зарегистрируйтесь.
Вам не пришло письмо с кодом активации?

Войти
 
  Начало   Форум  WIKI (Вики)FAQ Помощь Поиск Войти Регистрация  

Страниц: [1]   Вниз
  Печать  
Автор Тема: QFtp. Получить список доступных для скачивания файлов  (Прочитано 2618 раз)
cdsmika
Гость
« : Август 13, 2014, 18:00 »

Привет!

Подскажите как получить список доступных для скачивания файлов с фтп с помощью QFtp.
Делаю так:

Код:
void ImportJob::processFolder(const QUrlInfo & i)
{
    if (i.isDir())
    {
        ...
    }
    else
    {
        // проверяем доступность файла
        if ( i.isFile() && i.isValid() && i.isReadable() && i.name().contains(_regExp ) )
        {
            _filesFound++;
            _pendingFiles.append( _currentPath + QDir::separator() + i.name() );
        }
    }
}

Проблема в том, что у заливающегося файла  i.isValid() == true и i.isReadable() == true. Непонятно как с помощью QFtp сказать загрузчику подождать пока файл зальется до конца, а потом его скачать, если заливает файл не моя прога. Иначе скачивается неполный файл.
« Последнее редактирование: Август 13, 2014, 18:33 от cdsmika » Записан
cdsmika
Гость
« Ответ #1 : Август 13, 2014, 18:17 »

Цитировать
void QFtp::readyRead () [signal]
This signal is emitted in response to a get() command when there is new data to read.

If you specify a device as the second argument in the get() command, this signal is not emitted; instead the data is written directly to the device.

You can read the data with the readAll() or read() functions.

This signal is useful if you want to process the data in chunks as soon as it becomes available. If you are only interested in the complete data, just connect to the commandFinished() signal and read the data then instead.

See also get(), read(), readAll(), and bytesAvailable().
Копнуть в эту сторону?
Записан
cdsmika
Гость
« Ответ #2 : Август 13, 2014, 18:33 »

Получаю данные в commandFinished слоте.

Код:
case QFtp::Get:
            {
                setLastUpdate();

                if ( !ftp()->currentDevice() )
                {
                    criticalMessage( trUtf8("Buffer pointer is not valid!") );
                    return;
                }

                QBuffer * buf = qobject_cast<QBuffer*>( ftp()->currentDevice() );
                if ( !buf )
                {
                    criticalMessage( trUtf8("Buffer pointer is not valid!") );
                    return;
                }

                _currentFile = buf->property("fileName").toString();

                if (error)
                {
                    criticalMessage( trUtf8("Canceled download %1. %2")
                                   .arg( _currentFile )
                                   .arg( ftp()->errorString() ) );
                    {
                        buf->close();
                        buf = 0;
                        return;
                    }
                }

                // передаем текущий буфер для обработки
                if ( !_worker->setCurrentBuffer(buf) )
                    criticalMessage( trUtf8("Could not open buffer!") );

                break;
            }
Записан
cdsmika
Гость
« Ответ #3 : Август 14, 2014, 01:58 »

Сделал проверку:
Код:
void ...::ftpCommandFinished( int id, bool error )
{
    if (error)
    {
        if ( showDebugMessages() )
            criticalMessage( ftp()->errorString() );
        return;
    }
    .....
}
Тут выпадают случаи, когда файл на той стороне занят.
Записан
Страниц: [1]   Вверх
  Печать  
 
Перейти в:  


Страница сгенерирована за 0.08 секунд. Запросов: 20.