Copying contents of a folder
Posted: Wed May 18, 2016 9:41 am
This function only copies files in a folder from remote to source.But I need to modify this function to copy all the folders and its contents..Eg: FolderA contains Folder1,Folder2,Folder3, and Folder 1 contains file1,file2 and file3.Please help
Code: Select all
public function CopyFile($remote_file, $local_file)
{
$sftp = $this->sftp;
$stream = @fopen("ssh2.sftp://$sftp$remote_file", 'r');
if (! $stream)
throw new \Exception("Could not open file: $remote_file");
//$contents = stream_get_contents($stream);
$contents=@file_get_contents($remote_file);
@fclose($stream);
$stream = @fopen("ssh2.sftp://$sftp$local_file", 'w');
if (! $stream)
throw new \Exception("Could not open file: $local_file");
if (@fwrite($stream, $contents) === false)
throw new \Exception("Could not send data from file: $local_file.");
//file_put_contents ($local_file, $contents);
@fclose($stream);
$this->deleteFile($remote_file);
}