Establish, authenticate, and terminate an FTP connection.
<?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); // then do something… // close connection ftp_close($ftp_conn); ?> |
The ftp_connect()
function establishes an FTP connection to the specified host. Once connected, you can perform FTP operations on the server.
ftp_connect(host, port, timeout); |
Parameter |
Description |
host |
Mandatory. Specifies the FTP server to connect to, which can be a domain or IP address. Do not prefix this parameter with “ftp://” or include trailing slashes. |
port |
Optional. Specifies the port of the FTP server, with the default being port 21. |
timeout |
Optional. Specifies the timeout for all subsequent network operations, with a default of 90 seconds. |
Return Value: |
An FTP stream on success or |
PHP Version: |
4+ |
PHP Changelog: |
The |