Php ftp learning (1)

Source: Internet
Author: User
Tags ftp connection
ByVikramVaswaniMelonfireNovember07, 2000 & nbsp; We are a loyal FANS of a group of php (as the mainstream development language, we use it for various reasons-WEB site development, drawing, database connection, etc-we found that it is very friendly, powerful, and easy to use... By Vikram Vaswani
Melonfire
November 07,200 0
We are a loyal FANS of a group of php (as the mainstream development language). We use it for various reasons-WEB site development, drawing, database connection and so on-we found that it is very friendly, powerful, and easy to use ......
You may have seen how php (as a mainstream development language) is used to create GIF and JPEG images and dynamically retrieve information from the database, but this is only the tip of the iceberg-the latest version of php (as the mainstream development language) has a powerful file transfer function.
In this tutorial, I will show you how FTP transfers files through HTTP and FTP connections, as well as some simple program code. come with me!

First, you should know that php (as the mainstream development language) is used to transmit files through HTTP and FTP connections. Uploading files via HTTP has already appeared in php (as the mainstream development language) 3. now, the new FTP function is in the new php (as the mainstream development language) version!
Before you start, make sure that your php (as the mainstream development language) supports FTP. you can check the following code:

--------------------------------------------------------------------------------

Php (as the mainstream development language) info ();

?>
--------------------------------------------------------------------------------
Check the output result in the "Additional Modules" area, which lists the Modules supported by your php (as the mainstream development language). If you do not find the FTP module, you 'd better reinstall php (as the mainstream development language) and add FTP support!

Let's take a look at how a typical FTP task is completed!
--------------------------------------------------------------------------------
$ Ftp ftp.server.com
Connected to ftp.server.com
220 server.com FTP server ready.
Name (server: john): john
331 Password required for john.
Password:
230 User john logged in.
Remote system type is UNIX.
Using binary mode to transfer files.
Ftp> ls
200 PORT command successful.
150 Opening ASCII mode data connection for/bin/ls.
Drwxr-xr-x 5 john users 3072 Nov 2.
Drwxr-xr-x 88 root 2048 Nov 1 ..
Drwxr -- r -- 2 john users 1024 Oct 5 bin
Drwx -- x 8 john users 1024 Nov 2 public_html
Drwxr -- r -- 4 john users 1024 Nov 2 tmp
-Rw-r -- 1 john users 2941465 Oct 9 data.zip
226 Transfer complete.
Ftp> bin
200 Type set to I.
Ftp> get data.zip
Local: data.zip remote: data.zip
200 PORT command successful.
150 Opening BINARY mode data connection for data.zip (2941465 bytes ).
226 Transfer complete.
Ftp> bye
221 Goodbye.
--------------------------------------------------------------------------------
As you can see, the process is clearly divided into several segments: Connection (establish a connection with the FTP server), verification (determine whether the user has the right to enter the system), transmission (including the column Directory, upload or download files), cancel the connection.

Using php (as the mainstream development language) for FTP
Follow these steps to create an FTP connection for php (as the mainstream development language): Open a connection-send authentication information-use php (as the mainstream development language) function Manipulation directory and file transfer.
Specific implementation:
--------------------------------------------------------------------------------

// Connect to the FTP server
$ Conn = ftp_connect ("ftp.server.com ");

// Use username and password to log on

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.