PHP and FTP

PHP provides built-in functions that closely resemble standard FTP commands. In addition to transferring files, PHP allows your scripts to perform many administrative functions. Table 13-1 lists the most useful FTP commands supported by PHP.

Table 13-1. Common FTP Commands Supported by PHP

FTP Function (Where $ftp Is the FTP File Stream)

Usage

ftp_cdup($ftp);

Makes the parent directory the current directory

ftp_chdir ($ftp, "directory/path")

Changes the current directory

ftp_delete ($ftp, "file_name")

Deletes a file

ftp_get ($ftp, "local file", "remote file", MODE)

Copies the remote file to the local file where MODE indicates if the remote file is FTP_ASCII or FTP_BINARY

ftp_mkdir($ftp, "directory name")

Creates a new directory

ftp_rename($ftp, "file name")

Renames a file or a directory on the FTP server

ftp_put ($ftp, "remote file", "local file", MODE)

Copies the local file to the remote file where MODE indicates if the local file is FTP_ASCII or FTP_BINARY

ftp_rmdir($ftp, "directory/path")

Removes a directory

ftp_rawlist($ftp, "directory/path")

Returns an array with each array element containing directory information about a file

As shown in Table 13-1, the PHP FTP commands allow you to write webbots that create, delete, and rename directories and files. You may also use PHP/CURL to perform advanced FTP tasks requiring advanced authentication or encryption. Since FTP seldom uses these features, they are out of the scope of this book, but they're available for you to explore on the official PHP website available at http://www.php.net.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.8.127