MightyFtp (Add-ons)

Mighty FTP is simply the easiest way to interact with your FTP server with PHP on the web.

Mighty FTP is a powerful FTP client side library that wraps the complexities
of the core PHP FTP library and provides an intuitive api to interact with files on the FTP server.
With the library the user can get information about files, upload & download files, change file permissions,
rename files etc.

Intuitive Style

What makes the library so powerful is not so much the features that the library provides
but more so the in how a user can interact with the library.
This library will make it as easy to interact with files on any FTP server using PHP much in
the same way as jQuery revolutionized how Javascript developers can interact with the DOM.
Like jQuery MightyFTP utilizes a powerful design pattern called chaining which allows
developers to apply multiple interactions to a file on the FTP server with a single line of code.

Features of library

  • Easy FTP File/Directory traversal. Much like XML Node Traversal.
  • Access both FTP servers and secure FTP servers.
  • Access any file using absolute locations.
  • Upload files to remote an FTP directory.
  • Download files from an FTP directory.
  • Change FTP file permissions.
  • Get detailed information about files/directories.
  • Apply many operations to a file in a single line of code using chaining.

Core PHP FTP api vs Mighty FTP api

Presented below is an example of how easy it is to use the Mighty FTP Api vs the Core PHP FTP Api.
We have been tasked to rename a sub directory and change its permissions.
Using the Core PHP FTP Api

//Connect and Login
$conn_id = FTP_connect("sampleserver.com");
$login_result = FTP_login($conn_id, "sampleusername", "samplepassword");

$old_dir_name = 'olddirectoryname';
$new_dir_name = 'newdirectoryname';

//First attempt to rename the file. We are assuming that the current directory is root.
if (FTP_rename($conn_id, $old_dir_name, $new_dir_name)) {
 echo "successfully renamed $old_dir_name to $new_dir_name\n";
} else {
 echo "There was a problem while renaming $old_dir_name to $new_dir_name\n";
}

//Next change the file permissions.
if (FTP_chmod($conn_id, 0777, $new_dir_name) !== false) {
 echo "$file chmoded successfully to 777\n";
} else {
 echo "could not chmod $new_dir_name\n";
}

Using the MightyFTP Api

//Include MightyFTP/FTPClient.php
require_once("MightyFTP/FTPClient.php");

function renameAndChangePermissions()
{
    //Create MightyFTP\FTPClient on login to sampleserver.com
    $mightyFTPClient = new MightyFTP\FTPClient("sampleserver.com", new MightyFTP\FTPCredentials("sampleuser", "samplepassword"));

    //Get the root directory
    $rootDirectory = $mightyFTPClient->getRootDirectory();

    $rootChildren = $rootDirectory->getChildren();
    //Once you have a reference to the directory you can rename and chmod the directory in a single line of code.
    $rootChildren["olddirectoryname"]->rename("newdirectoryname")->chmod(0777);

    //If no exceptions have been thrown then assume that everything was successful
    echo "Successfully renamed olddirectoryname to newdirectoryname and changed permissions of directory to 777";
}

try
{
    renameAndChangePermissions();
}
catch(MightyFTP\FTPException $ex)
{
    //If an exception was thrown then print exception message.
    echo $ex->message();
}

Download MightyFtp (Add-ons)

Leave a Reply

Your email address will not be published. Required fields are marked *