PHP FTP 1.1

A freeware script enabling PHP scripts to make FTP connections

Download | Requirements | Limitations | Security | Usage Examples


Free Web Script Downloads

Requirements:


PHP FTP requires PHP version 4.3 or higher, with support for fsockopen enabled.

Limitations:


This script provides only the most basic of FTP services, which do not include the handling of data connections. "Then what is it good for?" you ask? If FTP functions are enabled in your server's PHP installation, maybe nothing. But if not, then this script is useful for doing anything that doesn't require a data connection. For example, I wrote it to provide an automatable way to set folder access permissions using the "site chmod" command.

Unblockable Exit Popup

Security:


We strongly recommend that you do not store your username and password in a PHP script unless only people you trust completely have access to your server. Instead, use a form to enter the username and password each time the script is run. Exercize caution with any system that transmits passwords over unencrypted connections.

Usage Examples:


Basic usage
NOTE: With PHP FTP versions before 1.1, the following code will not display error messages for certain types of connection failures. If you are using an older version, either upgrade to the current version or use the next code example.

<?php
require_once "PHPFTP.php";

$ftp = new PHPFTP();

// if the first argument to Connect is blank,
// PHPFTP will connect to the local host via 127.0.0.1
$result = $ftp->Connect('www.somewhere.com','login name','password');

if ($result == 0) {
$ftp->DoCommand('enter command here', $result_number, $result_text);
echo "$result_text ($result_number)";
$ftp->DoCommand('another command', $result_number, $result_text);
echo "$result_text ($result_number)";
// say Disconnect(0); to break the connection without explicitly logging out
$ftp->Disconnect();
}
?>


Display your own error messages
NOTE: With PHP FTP versions before 1.1, the show_connect_error option was not supported. If you are using an older version, either upgrade to the current version, or delete the line that sets show_connect_error.

<?php
require_once "PHPFTP.php";

$ftp = new PHPFTP();
$ftp->show_connect_error=0;

// if the first argument to Connect is blank,
// PHPFTP will connect to the local host via 127.0.0.1
$result = $ftp->Connect('www.somewhere.com','login name','password');

switch ($result) {
case 0:
$ftp->DoCommand('enter command here', $result_number, $result_text);
echo "$result_text ($result_number)";
$ftp->DoCommand('another command', $result_number, $result_text);
echo "$result_text ($result_number)";
// say Disconnect(0); to break the connection without explicitly logging out
$ftp->Disconnect();
break;
case 1:
echo '[PHP FTP] Connect failed: Unable to open network connection';
break;
case 2:
echo '[PHP FTP] Connect failed: Unknown host';
break;
case 3:
echo '[PHP FTP] Connect failed: Login failed';
break;
case 4:
echo '[PHP FTP] Connect failed: Your PHP version does not support PHP FTP';
break;
}
?>
Gecko Tribe, LLC
PO Box 5835
Grand Island, NE 68802
Voice Mail: 308-646-0543
 

"Somebody's leaving your website right
now because you don't have ExPop."

Invite them to stay a little longer.

More Information | Close Message