php ssh2scpsend,PHP ssh2_scp_recv 用法 手册 | 示例代码

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);

}?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值