phpseclib doesn't upload correct file contents

半城伤御伤魂 提交于 2019-12-01 10:48:01
Jakuje

If you would read through the documentation, you would find out that the second argument of the put() function is $data, therefore not the file path, but the actual data to write:

function put($remote_file, $data, $mode = NET_SFTP_STRING, $start = -1, $local_start = -1)

By default, NetSFTP::put() does not read from the local filesystem. $data is dumped directly into $remotefile. [...]

To upload a local file, the easiest way is to read the content into one variable that will be passed to the put() function:

$data = file_get_contents("logo.png");
$sftp->put("/some/path/logo.png", $data);

Edit: You are probably using a new version of phpseclib, which renamed these constants to make them more object-like. With a new version, you should use

$sftp->put("/some/path/logo.png", "logo.png", SFTP::SOURCE_LOCAL_FILE);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!