Php ftp learning (2) _ PHP Tutorial

Source: Internet
Author: User
Php ftp learning (2 ). ByVikramVaswaniMelonfireNovember07 and 2000 log on to the FTP server. PHP provides some functions that can obtain information about the system, files, and directories. Ftp_pwd () if you By Vikram Vaswani
Melonfire
November 07,200 0
After logging on to the FTP server, PHP provides some functions that can obtain information about the system, files, and directories.

Ftp_pwd ()
If you want to know your current directory, you need to use this function.
--------------------------------------------------------------------------------

// Get current location
$ Here = ftp_pwd ($ conn );

?>
--------------------------------------------------------------------------------
In case you need to know what system the server is running?
Ftp_systype () is provided to you in this regard.
--------------------------------------------------------------------------------

// Get system type
$ Server_ OS = ftp_cmdype ($ conn );

?>
--------------------------------------------------------------------------------
Regarding the PASV switch, PHP also provides a function that enables or disables PASV (1 indicates on)
--------------------------------------------------------------------------------

// Turn PASV on
Ftp_pasv ($ conn, 1 );

?>
--------------------------------------------------------------------------------

Now, you know where you are and who you are with. now we are going to browse through the directory-the ftp_chdir () function is used to implement this function, it accepts a directory name as a parameter.
--------------------------------------------------------------------------------

// Change directory to "public_html"
Ftp_chdir ($ conn, "public_html ");

?>
--------------------------------------------------------------------------------
If you want to return to the Directory (parent directory) where you are located, ftp_cdup () can help you achieve your wish. This function can return to the upper-level Directory.
--------------------------------------------------------------------------------

// Go up one level in the directory tree
Ftp_cdup ($ conn );

?>
--------------------------------------------------------------------------------
You can also create or move a directory, which uses the ftp_mkdir () and ftp_rmdir () functions. note: If ftp_mkdir () is successfully created, the new directory name will be returned.
--------------------------------------------------------------------------------

// Make the directory "test"
Ftp_mkdir ($ conn, "test ");

// Remove the directory "test"
Ftp_rmdir ($ conn, "test ");

?>
--------------------------------------------------------------------------------
Creating an FTP directory usually involves transferring files-let's get started!

First, upload the file. the ftp_put () function is competent for this responsibility. it requires you to specify a local file name, the uploaded file name, and the transfer type. For example, if you want to upload the "“abc.txt”" file and the name is" “xyz.txt ", The Command should be as follows:
--------------------------------------------------------------------------------

// Upload
Ftp_put ($ conn, "xyz.txt", "abc.txt", FTP_ASCII );

?>
--------------------------------------------------------------------------------
Download file:
The function provided by PHP is ftp_get (). It also requires a file name on the server, the downloaded file name, and the transmission type as the parameter. for example, if the server file is his.zip, download it to the terminal and name it hers.zip. the command is as follows:
--------------------------------------------------------------------------------

// Download
Ftp_get ($ conn, "hers.zip", "his.zip", FTP_BINARY );

?>
--------------------------------------------------------------------------------
PHP defines two modes as transmission modes: FTP_BINARY and FTP_ASCII. For more information about the two modes, see this article, for more information, see related books.




How can I list objects? (Using DIR? :))
PHP provides two methods: a simple list of file names and directories, and a detailed list of file size, permissions, creation time, and other information.
First, use the ftp_nlist () function, and second, use ftp_rawlist (). both functions require a directory name as the parameter. both return the Directory column as an array, and each element of the array is equivalent to a row in the list.
--------------------------------------------------------------------------------

// Obtain file listing
$ Filelist = ftp_nlist ($ conn ,".");

?>
--------------------------------------------------------------------------------
You must know the file size! Don't worry, here is a very easy function ftp_size (), which returns the size of the file you specified, using BITES as the unit. It should be noted that if it returns "-1", it means that this is a directory. in the following example, you will see the application of this function.
--------------------------------------------------------------------------------

// Obtain file size of file "data.zip"
$ Filelist = ftp_size ($ conn, "data.zip ");

?>

Http://www.bkjia.com/PHPjc/316109.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/316109.htmlTechArticleBy Vikram Vaswani Melonfire November 07,200 0 has logged on to the FTP server, and PHP provides functions that can get information about systems, files, and directories. Ftp_pwd () if you...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.