簡體   English   中英

phpseclib put 返回 true 但文件未上傳

[英]phpseclib put returns true but file is not uploaded

使用 PHP 插件 phpseclib v2.0.18 和 PHP 7.3,當我嘗試將文件上傳到 SFTP 服務器時, put()方法返回 true,但文件從未上傳。

日志說一切正常。

我的代碼:

foreach ($schedules as $idx => $schedule)
{
    $company = \Company::getItem($schedule->id_login);

    $outgoing_path = concat_path(BASE_PATH, 'pdf', 'file_schedules', $company->cif, 'outgoing', date('Ymd'));

    if (!is_dir($outgoing_path)) create_folder($outgoing_path, 0775, true);

    if ( ! ($sftp = new SFTP($schedule->host, $schedule->port)))
    {
        static::logError('No se pudo iniciar la conexión.', array($schedule->id_login, $company->name, $company->cif));
        continue;
    }

    if (!$sftp->login($schedule->user, $schedule->password))
    {
        static::logError('No se pudo hacer login en el servidor remoto.', array($schedule->id_login, $company->name, $company->cif));
        continue;
    }

    unset($schedule->password);

    if (!$sftp->chdir(concat_path($schedule->path, 'outgoing')))
    {
        static::logError('No se pudo acceder al directorio.', $schedule);
    }

    $dir_iterator = new \DirectoryIterator($outgoing_path);

    $count = 0;

    foreach ($dir_iterator as $file)
    {
        if ($file->isDot()) continue;

        if ($sftp->put($file->getPathname(), concat_path($sftp->pwd(), $file->getFilename(), SFTP::SOURCE_LOCAL_FILE)))
        {
            $count += 1;
        }
    }

    static::logInfo("$count archivos exportados.");
}

登錄沒問題。 本地和遠程路徑和文件名都很好。 下載文件的類似代碼工作正常。 文件權限沒問題。

我究竟做錯了什么?

日志output:

-> NET_SFTP_INIT (0s)
00000000  00:00:00:03                                      ....

<- NET_SFTP_VERSION (0.008s)
00000000  00:00:00:03:00:00:00:18:70:6f:73:69:78:2d:72:65  ........posix-re
00000010  6e:61:6d:65:40:6f:70:65:6e:73:73:68:2e:63:6f:6d  name@openssh.com
00000020  00:00:00:01:31:00:00:00:13:73:74:61:74:76:66:73  ....1....statvfs
00000030  40:6f:70:65:6e:73:73:68:2e:63:6f:6d:00:00:00:01  @openssh.com....
00000040  32:00:00:00:14:66:73:74:61:74:76:66:73:40:6f:70  2....fstatvfs@op
00000050  65:6e:73:73:68:2e:63:6f:6d:00:00:00:01:32:00:00  enssh.com....2..
00000060  00:14:68:61:72:64:6c:69:6e:6b:40:6f:70:65:6e:73  ..hardlink@opens
00000070  73:68:2e:63:6f:6d:00:00:00:01:31:00:00:00:11:66  sh.com....1....f
00000080  73:79:6e:63:40:6f:70:65:6e:73:73:68:2e:63:6f:6d  sync@openssh.com
00000090  00:00:00:01:31                                   ....1

-> NET_SFTP_REALPATH (0s)
00000000  00:00:00:01:2e                                   .....

<- NET_SFTP_NAME (0.003s)
00000000  00:00:00:01:00:00:00:0c:2f:55:73:65:72:73:2f:6a  ......../Users/j
00000010  6f:72:67:65:00:00:00:0c:2f:55:73:65:72:73:2f:6a  orge..../Users/j
00000020  6f:72:67:65:00:00:00:00                          orge....

-> NET_SFTP_OPENDIR (0s)
00000000  00:00:00:15:2f:55:73:65:72:73:2f:6a:6f:72:67:65  ..../Users/jorge
00000010  2f:6f:75:74:67:6f:69:6e:67                       /outgoing

<- NET_SFTP_HANDLE (0.0032s)
00000000  00:00:00:04:00:00:00:00                          ........

-> NET_SFTP_CLOSE (0s)
00000000  00:00:00:04:00:00:00:00                          ........

<- NET_SFTP_STATUS (0.0031s)
00000000  00:00:00:00:00:00:00:07:53:75:63:63:65:73:73:00  ........Success.
00000010  00:00:00                                         ...

-> NET_SFTP_OPEN (0.0001s)
00000000  00:00:00:6e:2f:55:73:65:72:73:2f:6a:6f:72:67:65  ...n/Users/jorge
00000010  2f:4d:45:47:41:73:79:6e:63:2f:77:6f:72:6b:73:70  /MEGAsync/worksp
00000020  61:63:65:2f:74:65:73:6f:72:69:7a:61:2f:6d:69:6c  ace/tesoriza/mil
00000030  65:73:74:6f:6e:65:73:2f:70:64:66:2f:66:69:6c:65  estones/pdf/file
00000040  5f:73:63:68:65:64:75:6c:65:73:2f:41:38:36:32:31  _schedules/A8621
00000050  32:34:32:30:2f:6f:75:74:67:6f:69:6e:67:2f:32:30  2420/outgoing/20
00000060  31:39:31:30:30:37:2f:50:72:75:65:62:61:2e:78:6c  191007/Prueba.xl
00000070  73:78:00:00:00:1a:00:00:00:00                    sx........

<- NET_SFTP_HANDLE (0.0047s)
00000000  00:00:00:04:00:00:00:00                          ........

-> NET_SFTP_WRITE (0s)
00000000  00:00:00:04:00:00:00:00:00:00:00:00:00:00:00:00  ................
00000010  00:00:00:23:2f:55:73:65:72:73:2f:6a:6f:72:67:65  ...#/Users/jorge
00000020  2f:6f:75:74:67:6f:69:6e:67:2f:50:72:75:65:62:61  /outgoing/Prueba
00000030  2e:78:6c:73:78:2f:31                             .xlsx/1

<- NET_SFTP_STATUS (0.0032s)
00000000  00:00:00:00:00:00:00:07:53:75:63:63:65:73:73:00  ........Success.
00000010  00:00:00                                         ...

-> NET_SFTP_CLOSE (0s)
00000000  00:00:00:04:00:00:00:00                          ........

<- NET_SFTP_STATUS (0.0031s)
00000000  00:00:00:00:00:00:00:07:53:75:63:63:65:73:73:00  ........Success.
00000010  00:00:00                                         ...

似乎沒事。

從您的代碼:

        if ($sftp->put($file->getPathname(), concat_path($sftp->pwd(), $file->getFilename(), SFTP::SOURCE_LOCAL_FILE)))
        {
            $count += 1;
        }

讓我們分解一些。 所以你這樣做:

$sftp->put(
    $file->getPathname(),
    concat_path($sftp->pwd(), $file->getFilename(), SFTP::SOURCE_LOCAL_FILE)
);

idk concat_path做了什么,但我猜你括號的位置是錯誤的。 我的猜測是你想這樣做:

$sftp->put(
    $file->getPathname(),
    concat_path($sftp->pwd(), $file->getFilename()),
    SFTP::SOURCE_LOCAL_FILE
);

無論如何,您在哪里尋找文件? 根據您的日志,它們應該顯示在/Users/jorge/MEGAsync/workspace/tesoriza/milestones/pdf/file_schedules/A86212420/outgoing/20191007/Prueba.xlsx 那是你要找的地方嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM