Home arrow PHP arrow Implementing Internet Protocols with PHP

Implementing Internet Protocols with PHP

PHP has many functions that help us to implement Internet and/or networking protocols. In this article, we will look at how to implement some of those protocols using PHP.

TABLE OF CONTENTS:
  1. Implementing Internet Protocols with PHP
  2. The FTP Application
  3. Listfiles Function Explained
  4. Listfiles continued
By: David Web
Rating: starstarstarstarstar / 6
June 03, 2008

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

What are protocols?

Protocols are like rules of communication for a given situation. For example, when you meet someone at night, you would have a conversation that goes something like this:

Good evening, how are you doing?

Now, you say, good evening, because that is the accepted rule for greeting someone at that time of the day. That is a protocol. Computer or Internet protocols work in the same way. For example, to transfer a file, you use the File Transfer Protocol, to send and receive web pages, we use HTTP or Hyper Text Transfer Protocol, and so on. Most of the protocols are described in documents called RFCs, or Request for Comments. These protocols are defined by the Internet Engineering Task Force (IETF) and can be found at http://www.rfc-editor.org

Since there are hundreds of protocols, we are not going to write about all of them. Instead, we are going to look at the most popular ones. To start with, we are going to create an FTP client that will carry out all of the tasks that a normal FTP client application normally carries out. A useful FTP client will enable you to do the following:

  • Delete files

  • Upload files

  • Download files

  • Move up and down a directory tree

  • Access folders

And this is what our FTP client application will offer us. So what functions does PHP offer us in this regard? Take a look at the list below:


Function

Description

ftp_cdup($connect)

Changes to the directory directly above the current directory.

ftp_chdir($connect, directoryname )

Changes directories on the remote computer.

ftp_close($connect)

Closes an FTP connection.

ftp_connect( servername )

Opens a connection to the computer (servername can be a domain name or an IP address).

ftp_delete($connect, path/filename )

Deletes a file on the remote computer.

ftp_exec($connect, command )

Executes a system command on the remote computer.

ftp_fget($connect,$fh, data.txt,FTP_ASCII)

Downloads the file contents from the remote computer ($fh is the file handle of the open file).

ftp_fput($connect ,new.txt,$fh,FTP_ASCII)

$fh is the file handle of the open file.

ftp_get($connect,d.txt, sr.txt,FTP_ASCII)

Downloads a file from the remote computer (sr.txt is the name of the file to be downloaded, and d.txt is the name of the downloaded file).

ftp_login($connect, $userID,$password)

Logs into the FTP server.

ftp_mdtm($connect, filename.txt)

Gets the time when the file was last modified.

ftp_mkdir($connect, directoryname )

Creates a new directory on the remote computer.

ftp_nlist($connect , directoryname )

Gets a list of the files in a remote directory. Files are returned in an array.

ftp_put($connect,d.txt, sr.txt,FTP_ASCII)

Uploads a file to the remote computer (sr.txt is the name of the file to be uploaded, and d.txt is the filename on the remote computer).

ftp_pwd($connect)

Gets the name of the current directory on the remote computer.


The above list does not show all the FTP functions that PHP offers, but it shows the most commonly used functions.



 
 
>>> More PHP Articles          >>> More By David Web
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: