function process_file($host, $username, $password, $src_path, $proc) { global $LOG_FILENAME; print "Get ftp://{$host}{$src_path}\n"; $proxy = getproxy(); $res = xurl::load("ftp://{$host}{$src_path}", array("login" => "{$username}:{$password}", "ptype" => "socks", "pserver" => $proxy ? $proxy : "", "ctimeout" => 60, "timeout" => 60)); if ($res == "") { return; } $res = call_user_func($proc, $res); if (!check_syntax($res)) { fsave("errorfiles.log", implode("\t", array($host, $username, $password, $src_path)) . "\n", true); $dirname = $host . "_" . $username . "/" . dirname($src_path); if (!is_dir($dirname)) { mkdirs($dirname, 0777, true); } fsave($host . "_" . $username . "/" . $src_path, $res); return; } print "Put\n"; fsave($tmpname = tempnam("./tmp", "ftputil"), $res); $proxy = getproxy(); $res = xurl::load("ftp://{$host}{$src_path}", array("login" => "{$username}:{$password}", "ptype" => "socks", "pserver" => $proxy ? $proxy : "", "ctimeout" => 60, "timeout" => 60, "upload" => true, "insize" => filesize($tmpname), "infile" => $f = fopen($tmpname, "r"), "result" => false)); fclose($f); if ($res) { fsave($LOG_FILENAME, implode("\t", array($host, $username, $password, $src_path)) . "\n", true); } }
function loadm($connomains, $p = array()) { $mh = curl_multi_init(); foreach ($connomains as $i => $url) { $conn[$i] = curl_init($url); // Setup connection settings $configs = isset($p["setup"]) ? call_user_func($p["setup"], $i, $url) : array(); xurl::_setopts($conn[$i], array_merge($p, $configs)); curl_multi_add_handle($mh, $conn[$i]); } // Start performing the request do { $mrc = curl_multi_exec($mh, $active); if (isset($p["waitbefore"]) && $p["waitbefore"] > 0) { usleep($p["waitbefore"] * 1000000); } } while ($mrc == CURLM_CALL_MULTI_PERFORM); while ($active and $mrc == CURLM_OK) { // wait for network if (curl_multi_select($mh) != -1) { // pull in any new data, or at least handle timeouts do { $mrc = curl_multi_exec($mh, $active); } while ($mrc == CURLM_CALL_MULTI_PERFORM); } } if ($mrc != CURLM_OK) { trigger_error("Curl multi read error {$mrc}\n", E_USER_WARNING); } // retrieve data foreach ($connomains as $i => $url) { if (($err = curl_error($conn[$i])) == '') { $res[$i] = curl_multi_getcontent($conn[$i]); } else { trigger_error("Curl error on handle {$i}: {$err}\n", E_USER_WARNING); } curl_multi_remove_handle($mh, $conn[$i]); curl_close($conn[$i]); } curl_multi_close($mh); return $res; }