| 533 | } |
| 534 | |
| 535 | int CChannelSFTP::AsyncFile() |
| 536 | { |
| 537 | for(auto it = m_vFiles.begin(); it != m_vFiles.end();) { |
| 538 | auto file = *it; |
| 539 | switch(file->state) { |
| 540 | case STATE::OPEN: { |
| 541 | int remoteFlag = O_WRONLY | O_CREAT | O_TRUNC; |
| 542 | int localFlag = O_RDONLY; |
| 543 | quint32 permission = file->fileTransfer->GetRemotePermission(); |
| 544 | |
| 545 | if(file->fileTransfer->GetDirection() == CFileTransfer::Direction::Download) { |
| 546 | remoteFlag = O_RDONLY; |
| 547 | localFlag = O_WRONLY | O_CREAT | O_TRUNC; |
| 548 | } |
| 549 | |
| 550 | file->remote = sftp_open( |
| 551 | m_SessionSftp, |
| 552 | file->fileTransfer->GetRemoteFile().toStdString().c_str(), |
| 553 | remoteFlag, permission); // S_IRWXU); |
| 554 | if (!file->remote) |
| 555 | { |
| 556 | file->state = STATE::ERR; |
| 557 | QString szErr = "Can't open remote file: " + file->fileTransfer->GetRemoteFile() |
| 558 | + ssh_get_error(m_Session); |
| 559 | file->fileTransfer->slotSetExplanation(szErr); |
| 560 | qCritical(log) << szErr; |
| 561 | break; |
| 562 | } |
| 563 | qDebug(log) << "Open remote file:" << file->fileTransfer->GetRemoteFile(); |
| 564 | |
| 565 | sftp_file_set_nonblocking(file->remote); |
| 566 | |
| 567 | file->local = ::open( |
| 568 | file->fileTransfer->GetLocalFile().toStdString().c_str(), |
| 569 | localFlag, permission); |
| 570 | if(-1 == file->local) { |
| 571 | file->state = STATE::ERR; |
| 572 | QString szErr = "Can't open local file: " + file->fileTransfer->GetLocalFile() + " " + strerror(errno); |
| 573 | file->fileTransfer->slotSetExplanation(szErr); |
| 574 | qCritical(log) << szErr; |
| 575 | break; |
| 576 | } |
| 577 | qDebug(log) << "Open local file:" << file->fileTransfer->GetLocalFile(); |
| 578 | |
| 579 | if(file->fileTransfer->GetDirection() == CFileTransfer::Direction::Download) { |
| 580 | #if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 11, 0) |
| 581 | if(ssh_version(SSH_VERSION_INT(0, 11,0))) { |
| 582 | sftp_limits_t lim = sftp_limits(m_SessionSftp); |
| 583 | if(lim) { |
| 584 | file->nChunkSize = lim->max_read_length; |
| 585 | qDebug(log) << "limits: max_open_handles:" << lim->max_open_handles |
| 586 | << "max_packet_length" << lim->max_packet_length |
| 587 | << "max_read_length" << lim->max_read_length |
| 588 | << "max_write_length:" << lim->max_write_length; |
| 589 | sftp_limits_free(lim); |
| 590 | } |
| 591 | |
| 592 | quint64 nRequestBytes = 0; |
nothing calls this directly
no test coverage detected