Complete collection of FTP operation functions in php (function description)

WBOY
Release: 2016-07-25 08:57:56
Original
959 people have browsed it
This article introduces the usage of ftp operation functions in PHP and the description of the main functions. Friends in need can refer to it.

The ftp operation functions in php mainly include:

ftp_connect: Open FTP link. ftp_login: Log in to the FTP server. ftp_pwd: Get the current path. ftp_cdup: Return to the upper directory. ftp_chdir: Change path. ftp_mkdir: Create a new directory. ftp_rmdir: Delete a directory. ftp_nlist: List all files in the specified directory. ftp_rawlist: List all files in the specified directory in detail. ftp_systype: Displays the server system. ftp_pasv: Switch active and passive transmission mode. ftp_get: Download files. ftp_fget: Download the file and save it in the opened file. ftp_put: Upload files. ftp_fput: Upload an open file. ftp_size: Get the size of the specified file. ftp_mdtm: Get the last modification time of the specified file. ftp_rename: Rename the file. ftp_delete: Delete the file. ftp_quit: Close the FTP connection.

The following is a detailed introduction to the ftp operation function in php.

ftp_connect Open FTP link. Syntax: int ftp_connect(string host, int [port]); Return value: integer Function type: Network system Content description: This function can open the link to the FTP server. The parameter host is the URL of the FTP server. The parameter port is usually omitted. This parameter is only needed if the port number of the FTP server is not 21. If there is no error, the connection code is returned, and if it fails, the false value is returned. Reference: ftp_quit()

ftp_loginLog in to the FTP server. Syntax: boolean ftp_login(int ftp_stream, string username, string password); Return value: Boolean value Function type: Network system Content description: This function can log in to the linked FTP server. The parameter ftp_stream is the FTP connection code. The parameters username and password are the user account and password of the server respectively. Usually anonymous is the public user account and the password is Email. Returns true value on success.

ftp_pwd Get the current path. Syntax: string ftp_pwd(int ftp_stream); Return value: string Function type: Network system Content description: This function is used to obtain the current path in the FTP server. The parameter ftp_stream is the FTP connection code. If there is an error, a NULL value is returned.

ftp_cdup Return to the upper directory. Syntax: boolean ftp_cdup(int ftp_stream); Return value: Boolean value Function type: Network system Content description: This function is used to return to the upper directory, which is the parent directory of the current directory. The parameter ftp_stream is the FTP connection code. Returns true value on success.

ftp_chdir Change path. Syntax: boolean ftp_chdir(int ftp_stream, string directory); Return value: Boolean value Function type: Network system Content description: This function is used to change the path. The parameter ftp_stream is the FTP connection code. The parameter directory is the directory you want to go to. Returns a true value on success and a false value on failure.

ftp_mkdirCreate a new directory. Syntax: string ftp_mkdir(int ftp_stream, string directory); Return value: string Function type: Network system Content description: This function is used to create a new directory. The parameter ftp_stream is the FTP connection code. The parameter directory is the new directory to be created. Returns the created directory name on success, false value on failure.

ftp_rmdir Delete directory. Syntax: boolean ftp_chdir(int ftp_stream, string directory); Return value: Boolean value Function type: Network system Content description: This function is used to delete empty directories. The parameter ftp_stream is the FTP connection code. The parameter directory is the directory to be deleted. Returns a true value on success and a false value on failure.

ftp_nlist List all files in the specified directory. Syntax: array ftp_nlist(int ftp_stream, string directory); Return value: array Function type: Network system Content description: This function is used to list all file names in the specified path. The parameter ftp_stream is the FTP connection code. The parameter directory is the specified directory. Returns an array of file names on success, false on failure.

ftp_rawlist List all files in the specified directory in detail. Syntax: array ftp_rawlist(int ftp_stream, string directory); Return value: array Function type: Network system Content description: This function can list all file names in the specified path in detail. The parameter ftp_stream is the FTP connection code. The parameter directory is the specified directory. Returns an array of file names on success, false on failure.

ftp_systype Display server system. Syntax: string ftp_systype(int ftp_stream); Return value: string Function type: Network system Content description: This function can display the system of the remote FTP server, which is equivalent to issuing the system or syst command to the FTP server. The parameter ftp_stream is the FTP connection code. If successful, a string is returned, such as: "215 UNIX Type: L8", if failed, a false value is returned.

ftp_pasv Switch active and passive transmission modes. Syntax: boolean ftp_systype(int ftp_stream); Return value: Boolean value Function type: Network system Content description: This function can switch to active transmission or passive transmission mode, which is equivalent to issuing the passive or pass command to the FTP server. The parameter ftp_stream is the FTP connection code. Returns a true value on success and a false value on failure.

ftp_get Download files. Syntax: boolean ftp_get(int ftp_stream, string local_file, string remote_file, int mode); Return value: Boolean value Function type: Network system Content description: This function is used to download the specified file. The parameter ftp_stream is the FTP connection code. The parameter local_file is the file name to be saved locally. The parameter remote_file is the name of the file to be downloaded. There are two values ​​for the parameter mode: FTP_ASCII and FTP_BINARY, which represent text files or binary files respectively. Returns a true value on success and a false value on failure.

ftp_fget Download the file and save it in the opened file. Syntax: boolean ftp_fget(int ftp_stream, int fp, string remote_file, int mode); Return value: Boolean value Function type: Network system Content description: This function is used to download the specified file. The parameter ftp_stream is the FTP connection code. The parameter fp is the file pointer of the opened file on the local side. The parameter remote_file is the name of the file to be downloaded. There are two values ​​of parameter mode: FTP_ASCII and FTP_BINARY, which represent text files or binary files respectively. Returns a true value on success and a false value on failure.

ftp_put Upload files. Syntax: boolean ftp_put(int ftp_stream, string remote_file, string local_file, int mode); Return value: Boolean value Function type: Network system Content description: This function is used to upload the specified file. The parameter ftp_stream is the FTP connection code. The parameter remote_file is the name of the file to be stored remotely. The parameter local_file is the file name of the file to be uploaded. There are two values ​​of parameter mode: FTP_ASCII and FTP_BINARY, which represent text files or binary files respectively. Returns a true value on success and a false value on failure.

ftp_fput Upload an open file. Syntax: boolean ftp_fput(int ftp_stream, string remote_file, int fp, int mode); Return value: Boolean value Function type: Network system Content description: This function is used to upload the specified file. The parameter ftp_stream is the FTP connection code. The parameter remote_file is the name of the file to be stored remotely. The parameter fp is the file pointer of the opened file to be uploaded. There are two values ​​of parameter mode: FTP_ASCII and FTP_BINARY, which represent text files or binary files respectively. Returns a true value on success and a false value on failure.

ftp_size Get the size of the specified file. Syntax: int ftp_size(int ftp_stream, string remote_file); Return value: integer Function type: Network system Content description: This function is used to obtain the size of the specified file on the FTP server. The parameter ftp_stream is the FTP connection code. The parameter remote_file is the name of the file to be obtained. The return value is the file size, or -1 on failure.

ftp_mdtm Get the last modification time of the specified file. Syntax: int ftp_mdtm(int ftp_stream, string remote_file); Return value: integer Function type: Network system Content description: This function is used to obtain the last modification time of the specified file on the FTP server. The parameter ftp_stream is the FTP connection code. The parameter remote_file is the name of the file whose modification time is to be obtained. The return value is UNIX time format (timestamp), or -1 value on failure.

ftp_rename Rename the file. Syntax: boolean ftp_rename(int ftp_stream, string from, string to); Return value: Boolean value Function type: Network system Content description: This function can rename the file on the remote FTP server. Please note that it cannot be changed if the permissions do not match. The parameter ftp_stream is the FTP connection code. The parameter from is the original file name. The parameter to is the new file name to be changed. Returns a true value on success and a false value on failure.

ftp_delete Delete the file. Syntax: boolean ftp_delete(int ftp_stream, string remote_file); Return value: Boolean value Function type: Network system Content description: This function can delete files on the remote FTP server. If the permissions do not match, the file cannot be deleted. The parameter ftp_stream is the FTP connection code. The parameter remote_file is the name of the file to be deleted. Returns a true value on success and a false value on failure.

ftp_quit Close the FTP connection. Syntax: boolean ftp_quit(int ftp_stream); Return value: Boolean value Function type: Network system Content description: This function is used to close the remote FTP server connection. The parameter ftp_stream is the FTP connection code. Returns a true value on success and a false value on failure.



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!