PHP SFTP 简单文件上传 [英] PHP SFTP Simple File Upload
问题描述
我正在使用 phpseclib - SFTP 类并且正在尝试上传这样的文件 -
I'm using phpseclib - SFTP class and am trying to upload a file like so -
$sftp = new Net_SFTP('mydomain.com');
if (!$sftp->login('user', 'password')) {
exit('Login Failed');
}
$sftp->put('/some-dir/',$fileTempName);
然而,文件并没有被上传到 some-dir
中,而是在之前上传了一个目录(到起始目录,假设它是根目录).这让我发疯了,我想我已经尝试了 some-dir/
或 /some-dir
或 /some-dir/
的所有组合>,但文件不会上传到那里.
The file however isn't being uploaded inside some-dir
but is uploaded one directory before (to the starting directory, lets say it's root). This is driving me crazy, I think I've tried all combinations of some-dir/
or /some-dir
or /some-dir/
, but the file won't upload there.
推荐答案
我不认为你的投入正在做你认为它正在做的事情.根据文档,你需要做一个 Net_SFTP::chdir('/some-dir/')
来切换到你想要发送文件的目录,然后 put($remote_file, $data)
,其中remote_file
为文件名,$data
为实际文件数据.
I don't think your put is doing what you think it is doing. According to the docs, you need to do a Net_SFTP::chdir('/some-dir/')
to switch to the directory you want to send file to, then put($remote_file, $data)
, where remote_file
is the name of file, and $data
is the actual file data.
示例代码:
<?php
include('Net/SFTP.php');
$sftp = new Net_SFTP('www.domain.tld');
if (!$sftp->login('username', 'password')) {
exit('Login Failed');
}
echo $sftp->pwd() . "\r\n";
$sftp->put('filename.ext', 'hello, world!');
print_r($sftp->nlist());
?>
这篇关于PHP SFTP 简单文件上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!