public function BackupMigrateDestinationSFTP::_save_file in Backup and Migrate SFTP 7
Save a local file to the remote server.
File
- ./
destinations.sftp.inc, line 31 - Functions to handle the SFTP backup destination.
Class
- BackupMigrateDestinationSFTP
- A destination for sending database backups to an SFTP server.
Code
public function _save_file($file, $settings) {
if (!$this
->sftpConnect()) {
return FALSE;
}
$source = $file
->filepath();
$filename = $file
->filename();
$sftp = $this->sftp;
$path = $this->dest_url['path'];
$stream = @fopen("ssh2.sftp://{$sftp}/{$path}/{$filename}", 'w');
if (!$stream) {
throw new Exception("Could not open remote stream.");
return FALSE;
}
$data = file_get_contents($source);
if (!$data) {
throw new Exception("Could not open source file.");
return FALSE;
}
if (@fwrite($stream, $data) === FALSE) {
throw new Exception("Could not transfer file.");
return FALSE;
}
@fclose($stream);
return $file;
}