PHP SFTP Simple File Upload
php, phpseclib, sftp
Solution
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.
Example Code:
<?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());
?>
Problem
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); ``` 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.