Skip to content

Instantly share code, notes, and snippets.

@mrinterweb
Created August 20, 2008 17:27
Show Gist options
  • Save mrinterweb/6409 to your computer and use it in GitHub Desktop.
Save mrinterweb/6409 to your computer and use it in GitHub Desktop.
protected function mySFTP($source_file, $destination_file){
if(!$this->connection) return false;
$sftp = ssh2_sftp($this->connection);
$sftpStream = fopen("ssh2.sftp://{$sftp}{$destination_file}", 'wb');
if($sftpStream) stream_set_blocking($sftpStream, true);
else return false;
try {
if (!$sftpStream)
throw new Exception("Could not open remote file: $destination_file");
$data_to_send = @file_get_contents($source_file);
if ($data_to_send === false)
throw new Exception("Could not open local file: $source_file.");
if (@fwrite($sftpStream, $data_to_send) === false)
throw new Exception("Could not send data from file: $source_file.");
} catch (Exception $e) {
$this->logError('Exception: ' . $e->getMessage());
}
fclose($sftpStream);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment