note 120942 added to function.ssh2-sftp
| From: | JarrodChristman | Date: | Wed, 05 Apr 2017 13:06:16 +0000 |
| Subject: | note 120942 added to function.ssh2-sftp | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-208981@lists.php.net to get a copy of this message | ||
David's code works wonderfully except for one thing, it wouldn't upload a file until I
placed a forward slash after '$sftp'
public function uploadFile($local_file, $remote_file)
{
$sftp = $this->sftp;
// Original
// "ssh2.sftp://$sftp$remote_file"
$stream = @fopen("ssh2.sftp://$sftp/$remote_file", 'w');
if (! $stream)
throw new Exception("Could not open file: $remote_file");
$data_to_send = @file_get_contents($local_file);
if ($data_to_send === false)
throw new Exception("Could not open local file: $local_file.");
if (@fwrite($stream, $data_to_send) === false)
throw new Exception("Could not send data from file: $local_file.");
@fclose($stream);
}
----
Server IP: 72.52.91.14
Probable Submitter: 98.103.160.18
----
Manual Page -- http://php.net/manual/en/function.ssh2-sftp.php
Edit -- https://master.php.net/note/edit/120942
Del: integrated -- https://master.php.net/note/delete/120942/integrated
Del: useless -- https://master.php.net/note/delete/120942/useless
Del: bad code -- https://master.php.net/note/delete/120942/bad+code
Del: spam -- https://master.php.net/note/delete/120942/spam
Del: non-english -- https://master.php.net/note/delete/120942/non-english
Del: in docs -- https://master.php.net/note/delete/120942/in+docs
Del: other reasons-- https://master.php.net/note/delete/120942
Reject -- https://master.php.net/note/reject/120942
Search -- https://master.php.net/manage/user-notes.php