从内网下载外网的文件或者将外网的文件上传,不能用ftp,只能用80端口,而且外网的文件不能被外人下载,也就是要实行加密,可以用linux,java,最好是php编写先谢谢各位了!急!!!

解决方案 »

  1.   

    我现在已用php编写了一段代码,主要是下面这条语句,它虽可以访问外网的文件,但这样很不安全,肯定是不行,不知谁有什么好的办法吗?
    $remotefile = @fopen ("http://100.80.1.1/mysqlbackup/20090904.sql", "rb");
    if (!$remotefile) {
            echo "<p>Unable to open remote file.\n";
            exit;
    }
    $line="";
    while (!feof ($remotefile)) {
            $line .=@fgets ($remotefile, 1024);}fclose($remotefile);$tempfile="/var/www/html/mysqlbackup/20090908.sql";
    $localfile=@fopen($tempfile,"wb");
    @fwrite($localfile,$line);
    fclose($localfile);
      

  2.   

    服务器server.php
    <?php
    if (isset ($_POST)) {
    $login_name = $_POST[username];
    $login_password = $_POST[password];
    $login_ip = $_POST[ip];
    //如果为了安全,用户名、密码及IP可以从数据库中存储
    if ($login_name=="liu" and $login_password=="123" and $login_ip=="19.16.16.252"){
    echo "right";
    $filename = "/bak1/test.txt";
    header("Content-Type: application/force-download");
    header("Content-Disposition: attachment; filename=".basename($filename));
    $line=readfile($filename);
    }else{
    die("wrong");
    }  
    }
    exit;
    ?>
    客户端client.php
    <?php
    $url='http://11.8.14.3/mysqlbackup/server.php';
    $fields = "username=liu&password=123&ip=192.168.166.252"; 
    $fp=fopen("test.txt",wb);
    $ch = curl_init();
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_FILE, $fp);
    curl_setopt($ch, CURLOPT_POST, 1 );
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 ); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields ); 
    curl_setopt($ch, CURLOPT_HEADER, 0);
    $str=curl_exec($ch);
    fwrite($fp,$str);
    fclose($fp);
    curl_close($ch);  
    ?>