php - PHP 尝试通过 SFTP 下载文件但在计算文件大小时收到 stat failed 错误
问题描述
尝试从 SFTP 位置下载文件。
我intval
在流上使用它,因为它旨在修复我在这里读到的错误:PHP 7 SSH2.SFTP stat() bug work around。我正在运行 PHP 7.0.33。
但是,它仍然在filesize
命令上失败
$connection = ssh2_connect('remote.host', 22);
ssh2_auth_password($connection, 'user', 'pass');
$sftp = ssh2_sftp($connection);
$remoteDir = '/Data/';
$handle = opendir("ssh2.sftp://".intval($sftp)."$remoteDir"); //works with intval, fails without
while (false !== ($entry = readdir($handle))){
$local = fopen('localdata/'.$entry, 'w');
$remote = fopen("ssh2.sftp://".intval($sftp)."$remoteDir$entry", 'r'); //works with intval, fails without
$fileSize = filesize("ssh2.sftp://".intval($sftp)."$remoteDir$entry"); //fails with or without intval
$buffer = fread($remote, $filesize - $read);
fwrite($local, '$buffer');
}
错误是:
PHP Warning: filesize(): stat failed for ssh2.sftp://5/ Data/remote_file.csv in /var/www/html/sftp_test.php on line 58
Segmentation fault
我不明白为什么opendir
并且fopen
工作但filesize
失败了。任何指导将不胜感激。
谢谢
更新:
我放弃了试图让它发挥作用。我正在使用它。不太复杂,但它可以完成工作
copy("ssh2.sftp://".intval($sftp)."/{$remoteDir}{$file}", "localdata/$file");
解决方案
推荐阅读
- javascript - JavaScript ES6 类是否违反函数式编程风格?
- powerbi - 发布 power bi 报告的脚本
- node.js - Firebase 功能因印地语字符而出现故障
- python - 有效地将长度为 n 的列表的 pandas 数据帧转换为 n 个数据帧
- laravel - 从多对多数据透视表上的 withPivot 获取关系数据
- java - 如何仅在 *.AUD 表而不是实体中添加特定列?
- ssh - 如何使用其他端口连接远程 SSH VS Code 扩展
- javascript - 在 Typescript 中键入非确定性深度数组
- python - 如何在 Google Colab 的笔记本中显示图像(如在 Anacondan Jupyter Notebook 中)?
- python - 如何在 Discord.py 重写中赋予某人一个角色