通过phpseclib将文件上传到特定目录

时间:2014-04-08 07:19:33

标签: php amazon-ec2 amazon phpseclib

您好我在将文件上传到文件夹时遇到问题,我的代码如下:

set_time_limit(0);
include('Net/SFTP.php');
include('Crypt/RSA.php');
$key = new Crypt_RSA();
$key->loadKey(file_get_contents('key/key.pem'));
$sftp = new Net_SFTP('ec2-xx-xx-xx-xxx.compute.amazonaws.com');
if (!$sftp->login('root', $key)) {
    exit('Login Failed');
}
else{
    echo'Login Successfull';
}
echo '<br>';
print_r($sftp->nlist($sftp->chdir("new_folder")));
echo '<br>';
$sftp->put('file.txt', 'hello, world!');

问题是即使将目录更改为new_folder也是如此。它将文件放在根文件夹中。任何帮助都会非常值得赞赏。 输出nlist

Array ( [0] => etc [1] => selinux [2] => srv [3] => dev [4] => boot [5] => smnt [6] => sbin [7] => image [8] => opt [9] => var [10] => . [11] => tmp [12] => sys [13] => new_folder [14] => lost+found [15] => .. [16] => .kconfig [17] => mnt [18] => lib [19] => root [20] => .profile [21] => lib64 [22] => home [23] => proc [24] => isa_home [25] => bin [26] => usr ) 

1 个答案:

答案 0 :(得分:0)

谢谢大家,我使用以下代码解决了这个问题:

$success_t = $sftp->put($remote_directory . $temps_file,$local_directory . $temps_file);