3.3. Using FTP

Transferring files from one computer to another happens a gazillion times a day on the Internet. When colleagues on opposite sides of the country need to share files, it's not a problem. A quick transfer takes only seconds, and all parties have the files they need.

FTP (File Transfer Protocol) is a common way to transfer files from one computer to another. FTP allows you to get a directory listing from another computer or to download or upload a single file or several files at once.

FTP is client/server software. To use FTP to transfer files between your computer and a remote computer, you connect to an FTP server on the remote computer and send it requests.

To use FTP in your scripts, FTP support needs to be enabled when PHP is installed. If you installed PHP for Windows, you don't need to do anything extra to enable FTP support. If you're compiling PHP on Unix, Linux, or Mac and you want to enable FTP support, you can use the FTP support installation option, as follows:

--enable-ftp

3.3.1. Logging in to the FTP server

To connect to the FTP server on the computer you want to exchange files with, use the ftp_connect function, as follows:

$connect = ftp_connect("janet.valade.com");

Or, you can connect by using an IP address, as follows:

$connect = ftp_connect("172.17.204.2");

After you connect, you must log in to the FTP server. You need a user ID and a password to log in. You might have your own personal ID and password, or you might be using a general ID and password ...

Get PHP & MySQL® Web Development All-in-One Desk Reference for Dummies® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.