php 调用shell实现文件下载功能
用php来实现远程文件下载,所以考虑到了用shell结合php来实现
shell脚本如下:
#!/usr/bin/expect -f
####set ip address ##############
set ip [lindex $argv 0 ]
####set username ################
set username [lindex $argv 1 ]
####set password ###############
set password [lindex $argv 2 ]
###########
set src_ [lindex $argv 3 ]
set timeout 10
spawn scp -r $username@$ip:$src_ /download/aa
expect {
"*yes/no" { send "yes\r"; exp_continue}
"*password:" { send "$password\r" }
}
expect "#*"
#send "ls -la /usr/local/\r"
#send "exit\r"
#expect eofphp文件如下:
<?php $ip = '127.0.0.1';//ip地址 $username = 'root'; //用户名 $passwd = 'wangjian'; $src_ = '/etc/'; $des_ = '/download/aa' ; //本地的路径 $scmd = "/sh/test1.sh ".$ip.' '.$username.' '.$passwd.' '.$src_.' '.$des_ ; $s = exec($scmd,$array,$status); echo $s ; echo '<pre>'; print_r($array);
浙公网安备 33010602011771号