Problem:
can't pass an array to sftp_scp_rec()
also: for Windows: sftp was not happy when connecting to a Windows dir.
eg: sftp_scp_rec($connection, "remote/directory","local/$directory[$i]");
Solution:
The array was placing whitespace on the end of the variable.
trim(" ","",$directory[$i]);
connecting to Windows dir:
sftp_scp_rec($connection, "linux/directory","\windowsshare[$i]");
This script backs up remote Linux directories to a local Windows directory based on modified dates of files.
The Idea is to get a complete back up of a directory via ftp client etc.
Then when the script runs it will back up newly modified files only.
foreach ($remotedirsas$val){
echo$remotedir="/data/www/$val/";$localdir="\\192.168.0.234\C$\xampp\htdocs\$val\";backupwebsites($remotedir,$localdir);
}
functionbackupwebsites($remotedir,$localdir){$connection=ssh2_connect(Host IPorDomain,22);$com="ls -R -lt$remotedir";ssh2_auth_password($connection,'user','password');$stream=ssh2_exec($connection,$com);stream_set_blocking($stream,true);$output=stream_get_contents($stream);$fh=fopen("c:dirlist.txt","a+");fwrite($fh,$output);fclose($fh);$handle= @fopen('c:dirlist.txt',"r");
if ($handle) {
while (!feof($handle)) {$lines[] =fgets($handle,4096);
}fclose($handle);
}
foreach ($linesas$val)
{$yr=date('Y-m-d');$i++;$arr1=split("200",$val);$arr2=explode(" ",$arr1[1]);
if("200".$arr2[0]==$yr)
{//if("200".$arr2[0]=='2008-04-21'){ //for testing$remotedir=$remotedir.$arr2[2];$cpy=$arr2[2];$file=$localdir;glue($connection,$remotedir,$localdir,$cpy);
}
}
}//echo $i;functionglue($connection,$remotedir,$localdir,$cpy){$ldir[0] ="$localdir";$ldir[1]="$cpy";$file=$ldir[0].$ldir[1];$file=trim($file);$file;gop($connection,$remotedir,$file);
}
functiongop($connection,$remotedir,$file){
echo$file;ssh2_scp_recv($connection,$remotedir,$file);
}?>