【问题标题】:Why phpseclibsftp returns "The directory '%s' does not exist and could not be created (%s)."?为什么 phpseclibsftp 返回“目录 '%s' 不存在且无法创建 (%s)。”?
【发布时间】:2020-07-22 11:36:28
【问题描述】:

调用时

$fileSystem = $this->filesystemMap->get(IMReporter::FILE_SYSTEM_SFTP_NAME);
$fileSystem->write($filename, file_get_contents($tempFile));

我得到目录“/home/darius/Desktop/veracitytest”不存在,无法创建()。

我已创建目录并手动将权限设置为 777。调试时我看到它调用

protected function ensureDirectoryExists($directory, $create)
{
    $pwd = $this->sftp->pwd();
    if ($this->sftp->chdir($directory)) {
        $this->sftp->chdir($pwd);
    } elseif ($create) {
        if (!$this->sftp->mkdir($directory, 0777, true)) {
            throw new \RuntimeException(sprintf('The directory \'%s\' does not exist and could not be created (%s).', $this->directory, $this->sftp->getLastSFTPError()));
        }
    } else {
        throw new \RuntimeException(sprintf('The directory \'%s\' does not exist.', $this->directory));
    }
}

它调用 !$this->sftp->mkdir($directory, 0777, true)

在mkdir中有这样的代码

if (!($this->bitmap & SSH2::MASK_LOGIN)) {
    return false;
}

它返回 false,所以我得到了错误。

$this->bitmap 是 7。我不明白它在这里试图做什么。在库中有这样的评论:

 /**
     * Execution Bitmap
     *
     * The bits that are set represent functions that have been called already.  This is used to determine
     * if a requisite function has been successfully executed.  If not, an error should be thrown.
     *
     * @var int
     * @access private
     */
var $bitmap = 0;

到目前为止,我还没有找到将它设置为 7 的位置。

使用https://github.com/phpseclib/phpseclib2.0

【问题讨论】:

    标签: php sftp phpseclib


    【解决方案1】:

    找到答案 - 我在输入错误密码时收到此消息。

    【讨论】:

    • 是的 - 就是这样 - 因为登录失败 $this->bitmap 永远不会与 SSH2::MASK_LOGIN 进行“或”运算,因此 if (!($this->bitmap & SSH2::MASK_LOGIN)) { 返回 false 并因此引发 \RuntimeException 异常。
    猜你喜欢
    • 1970-01-01
    • 2017-10-03
    • 2020-01-03
    • 1970-01-01
    • 2011-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-27
    相关资源
    最近更新 更多