PHP ftp_pasv() Function
Example
Turn passive mode on and upload a file to the FTP server:
<?php
// connect and login to FTP server
$ftp_server = "ftp.example.com";
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);
// turn passive mode on
ftp_pasv($ftp_conn, true);
$file = "localfile.txt";
// upload file
if (ftp_put($ftp_conn, "serverfile.txt", $file, FTP_ASCII))
{
echo "Successfully uploaded $file.";
}
else
{
echo "Error uploading $file.";
}
// close connection
ftp_close($ftp_conn);
?>
Definition and Usage
The ftp_pasv() function turns passive mode on or off.
In passive mode, data connections are initiated by the client, not the server. This is useful if the client is behind a firewall.
Syntax
ftp_pasv(ftp_connection,pasv);
Parameter | Description |
---|---|
ftp_connection | Required. Specifies the FTP connection to use |
pasv | Required. Specifies the passive mode. Possible values:
|
Technical Details
Return Value: | Returns TRUE on success or FALSE on failure |
---|---|
PHP Version: | 4+ |
❮ PHP FTP Reference