Question

Hi I am facing a problem while uploading a file to a folder, My Code is following:

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!');

The problem is that even after changing the directory to new_folder. it is putting the file inside root folder. Any help would be highly appreciable. output of 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 ) 
Was it helpful?

Solution

Thanks everyone i had solved this issue using following code:

$success_t = $sftp->put($remote_directory . $temps_file,$local_directory . $temps_file);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top