","\""),array("&","<",">","""),$what); } function unfilterHTML($what){ return str_replace(array("<",">",""","&"),array("<",">","\"","&"),$what); } $scriptName=basename($_SERVER["SCRIPT_NAME"]); $scriptName=filterHTML($scriptName); if($do=="getSource"){ // Download method depends on the browser $user_agent=strtolower($_SERVER["HTTP_USER_AGENT"]); header("Content-type: application/force-download"); if((is_integer(strpos($user_agent,"msie")))&&(is_integer(strpos($user_agent,"win")))){ header("Content-Disposition: filename=\"zip2sftp.php\""); }else{ header("Content-Disposition: attachment; filename=\"zip2ftp.php\""); } header("Content-Description: File Transfert"); // Send file readfile($scriptName); // Send e-mail if needed (for usage statistics) if (strpos($user_agent,"bot") === false && strpos($_SERVER["SERVER_NAME"], "alishomepage.com") === false) { mail( "opensource@alishomepage.com", "ZIP2SFTP Interface (Remote Edition): another one downloaded :)", "This part will be referred to when the browser sends out no referrer information\n\n" . "Server name: ".$_SERVER["SERVER_NAME"]."\n" . "Script name: ".$_SERVER["SCRIPT_NAME"]."\n" . "Translated path: ".$_SERVER["PATH_TRANSLATED"]."\n\n" . "Downloader's info (the referrer is most useful, user agent is to detect bots)\n\n" . "User agent: ".$_SERVER["HTTP_USER_AGENT"]."\n" . "Referrer: ".$_SERVER["HTTP_REFERER"]."\n" . "Request URL: ".$_SERVER["REQUEST_URI"]); } die(); } $port=intval($port); if(!$port || $port<1 || $port>65535){ $port=22; } // PHP < 5 didn't have sys_get_temp_dir if(!is_callable('sys_get_temp_dir',false)) { function sys_get_temp_dir() { $temp=""; if($temp=getenv('TMP')){ return $temp; } if($temp=getenv('TEMP')){ return $temp; } if($temp=getenv('TMPDIR')){ return $temp; } $temp=tempnam('', ''); if(file_exists($temp)){ unlink($temp); return dirname($temp); } return $temp; } } // On some systems, the zip functions do not exist. In this case, try to use // the "unzip" command (available by default on most Linux systems) // Code written by bisqwit at iki dot fi on the zip_open function's comments // on the PHP manual. Thanks to Radek from Poland for telling me about it. if(!is_callable("zip_open",false)){ function ShellFix($s) { return "'". str_replace("'", "'\''", $s)."'"; } function zip_open ($s) { $fp = @fopen ($s, 'rb'); if(!$fp ) return false; $lines = Array(); $cmd = 'unzip -v '.shellfix( $s); exec($cmd, $lines); $contents = Array(); $ok=false; foreach($lines as $line) { if($line[0]== '-') { $ok=!$ok; continue; } if(!$ok) { continue; } $length = (int)$line ; $fn = trim(substr ($line,58)); $contents[] = Array('name' => $fn, 'length' => $length); } return Array('fp' => $fp, 'name' => $s , 'contents' => $contents , 'pointer' => -1); } function zip_read(&$fp) { if(!$fp ) return false; $next = $fp ['pointer'] + 1; if( $next >= count($fp['contents' ])) return false; $fp['pointer' ] = $next; return $fp['contents'][$next]; } function zip_entry_name (&$res) { if(!$res) return false ; return $res['name' ]; } function zip_entry_filesize(&$res ) { if(!$res) return false; return $res['length']; } function zip_entry_open (&$fp, &$res) { if(!$res ) return false; $cmd = 'unzip -p '.shellfix($fp['name' ]).' '.shellfix($res[ 'name']); $res['fp'] = popen($cmd, 'r'); return !! $res['fp']; } function zip_entry_read(&$res, $nbytes) { $contents = ''; while (!feof($res['fp'])) { $contents .= fread($res['fp'], 8192); } return $contents; } function zip_entry_close(&$res) { fclose($res['fp' ]); unset($res['fp']); } function zip_close(&$fp) { fclose( $fp['fp']); } } ?> ZIP 2 SFTP

Ali's ZIP 2 SFTP Interface

PHP SSH2 extensions."; die(); } if($serverName){ if(strpos($zipFile,"http://")!==0 && strpos($zipFile,"https://")!==0 && strpos($zipFile,"ftp://")!==0){ echo "Please give an HTTP, HTTPS or FTP resource address!"; }else{ echo "
"; if(!$username || strlen($username)<1) { $username="anonymous"; } $portNumber=intval($portNumber); if(!$portNumber || $portNumber<1 || $portNumber>65535){ $portNumber=22; } $zip=zip_open($_FILES["uplFile"]["tmp_name"]); $uplTotal=0; if($zip){ if($conn_id=ssh2_connect($serverName,$portNumber)){ if(ssh2_auth_password($conn_id,$userName,$passWord)){ if($conn_sftp=ssh2_sftp($conn_id)){ $folder=str_replace(array("&slash;","&"),array("/","&"),stripslashes(str_replace(array("<","&","\\\\"),array("<","&","&slash;"),$folder))); if(strlen($folder)<1){ $folder="."; } if($folder[0]!=='/'){ $folder=ssh2_sftp_realpath($conn_sftp,$folder); } if(!file_exists("ssh2.sftp://$conn_sftp$folder")){ if(!ssh2_sftp_mkdir($conn_sftp,$folder,0750,true)){ echo "Cannot change current directory to $folder. Please check that the user has the correct access to create folders.\n"; die(); } } echo "Changed current directory to $folder