我們收到此錯誤:如何指定在PHP代碼中的端口
Warning: ftp_get(): Could not open data connection to port 51461: Connection timed out in /home/USER/public_html/SCRIPT/fetch_scripts/noose.php on line 39
第39行:
ftp_get($CONNECTION_ID, '../ftp-in' . $SAVE_DIRECTORY . "/" . $SAVE_FILE_AS, $FTP_REMOTE_FILENAME, FTP_ASCII);
但最初的FTP設置如下,有沒有辦法來映射端口需要21這個網站?
<?
ini_set("display_errors", "1");
error_reporting(-1);
//-------SYSTEM COMMANDS-------//
set_time_limit(0);
$start_time = time();
//-------CONFIGURE START-------//
$remote_server = 'ftp.SITE.com';
$remote_username = 'SITEFEED';
$remote_password = 'PASSWORD';
$remote_file = 'DATA.csv';
$local_save_path = '/DIRECTORY';
$local_save_filename = 'FILE.txt';
//-------CONFIGURE END-------//
//-------EXECUTION CODE-------//
fetch($remote_server,$remote_username,$remote_password ,$remote_file,$local_save_path, $local_save_filename);
//-------FUNCTIONS-------//
function fetch($FTP_SERVER,$FTP_USERNAME,$FTP_PASSWORD,$FTP_REMOTE_FILENAME,$SAVE_DIRECTORY,$SAVE_FILE_AS){
//MAKE CONNECTION...
$connected = 1;
$CONNECTION_ID = ftp_connect($FTP_SERVER);
if(!($CONNECTION_ID)){
echo "<font color = 'red'>Could not connect to FTP_SERVER: " . $FTP_SERVER . ".</font><br>";
$connected = 0;
}
$login_result = ftp_login($CONNECTION_ID,$FTP_USERNAME,$FTP_PASSWORD);
if((!$login_result)){
echo "<font color = 'red'>Check FTP_USERNAME & FTP_PASSWORD for " . $FTP_SERVER . ".</font><br>";
$connected = 0;
}
//IF CONNECTED...
if($connected == 1){
if(!is_dir('../ftp-in' . $SAVE_DIRECTORY)) { mkdir('../ftp-in' . $SAVE_DIRECTORY); }
ftp_get($CONNECTION_ID, '../ftp-in' . $SAVE_DIRECTORY . "/" . $SAVE_FILE_AS, $FTP_REMOTE_FILENAME, FTP_ASCII);
}
}
echo "<table><tr><Td><b>PAL FTP File Downloaded:</b></td><td>ftp-in/DATA/FILE.txt</td><td><i>Total Time: " . (time() - $start_time) . " seconds.</i></td></tr>";
$start_time = time();
include("../db_import_scripts/pal_db_import.php");
?>
端口21是FTP控制連接的默認。該錯誤可能是指使用臨時端口的數據連接。 – Barmar
以下是確切代碼:<嘗試添加但太長> –
請勿嘗試在註釋中放置代碼,編輯問題。 – Barmar