返回目前 FTP 被動模式是否打開

ftp_pasv

(PHP 4, PHP 5, PHP 7, PHP 8)

ftp_pasv — 返回目前 FTP 被動模式是否打開

說明

ftp_pasv(resource $ftp_stream, bool $pasv): bool

在被動模式打開的情況下,數據的傳送由客戶機啟動,而不是由伺服器開始。

請注意 ftp_pasv() 只能在 FTP 登錄成功後方可呼叫,否則會失敗。

參數

ftp_stream

FTP 連線資源。

pasv

如果參數 pasv 為 true,打開被動模式傳輸 (PASV MODE) ,否則則關閉被動傳輸模式。

返回值

成功時返回 true, 或者在失敗時返回 false。

範例

示例 #1 ftp_pasv() 實例

<?php
$file 
= 'somefile.txt';
$remote_file = 'readme.txt';

// set up basic connection
$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// turn passive mode on
ftp_pasv($conn_id, true);

// upload a file
if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
 echo 
"successfully uploaded $file\n";
} else {
 echo 
"There was a problem while uploading $file\n";
}

// close the connection
ftp_close($conn_id);
?>

Leave a Reply

Your email address will not be published. Required fields are marked *