FTP Learning in PHP (ii)

Source: Internet
Author: User
Tags file size ftp parent directory requires zip
by Vikram Vaswani
Melonfire
November 07, 2000
Logged on to the FTP server, PHP provides functions that can get information about systems and 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);

?>
--------------------------------------------------------------------------------
What if you need to know what system is running on the server side?
Ftp_systype () provides you with this information.
--------------------------------------------------------------------------------
?

Get system Type
$server _os = Ftp_systype ($conn);

?>
--------------------------------------------------------------------------------
On the passive mode (PASV) switch, PHP also provides such a function, it can turn on or off PASV (1 means open)
--------------------------------------------------------------------------------
?

Turn PASV on
FTP_PASV ($conn, 1);

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

Now that you know where you are and who is with you, now we're going to go around the table of contents--The Ftp_chdir () function, which takes a directory name as an argument.
--------------------------------------------------------------------------------
?

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

?>
--------------------------------------------------------------------------------
If you want to go back to the directory you're in (the parent directory), Ftp_cdup () can help you achieve your wish, and this function can go back to the previous directory.
--------------------------------------------------------------------------------
?

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

?>
--------------------------------------------------------------------------------
You can also create or move a directory, using the Ftp_mkdir () and Ftp_rmdir () functions; note: if Ftp_mkdir () is successful, it will return the newly created directory name.
--------------------------------------------------------------------------------
?

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

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

?>
--------------------------------------------------------------------------------
Creating an FTP directory is usually the transfer of files---so let's get started!

First upload file, Ftp_put () function is very good for this responsibility, it requires you to specify a local file name, uploaded file name and the type of transmission. For example: If you want to upload "abc.txt" This file, after uploading the name "Xyz.txt", the order should be this:
--------------------------------------------------------------------------------
?

Upload
Ftp_put ($conn, "Xyz.txt", "Abc.txt", ftp_ascii);

?>
--------------------------------------------------------------------------------
Download file:
PHP provides the function is Ftp_get (), it also requires a server file name, download the file name, as well as transport type as parameters, such as: Server-side files for His.zip, you want to download to the local machine, and named Hers.zip, the command is as follows:
--------------------------------------------------------------------------------
?

Download
Ftp_get ($conn, "Hers.zip", "His.zip", ftp_binary);

?>
--------------------------------------------------------------------------------
PHP defines two modes as transmission mode Ftp_binary and FTP_ASCII, the use of these two models to see two cases, as for its detailed explanation, this article also said, please refer to the relevant books.




How can I make a list of documents? (with Dir?) :) )
PHP offers two methods: one is to simply list the file name and directory, and the other is to specify the file size, permissions, time of creation, and so on.
The first type uses the Ftp_nlist () function, and the second uses the Ftp_rawlist (). Two functions require a directory name as a parameter, which returns a catalog column as an array, each of which corresponds to a row of the list.
--------------------------------------------------------------------------------
?

Obtain file Listing
$filelist = Ftp_nlist ($conn, ".");

?>
--------------------------------------------------------------------------------
You must want to know the size of the file! Don't worry, there's a very easy function ftp_size (), which returns the size of the file you specified, using bites as your unit. To point out, if it returns "-1", it means that this is a directory, and 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");

?>

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.