FTP Check

Recently I came up with the need to test multiple ftp accounts on a server. The server has been setup using proftpd, with mysql as the backend for the authentication and qoutas.

Anyways so here is the small script which I put together. It does not use the db but can be easily modified to use the db and run tests on multiple accounts. Place this script on the host where you want to test and call it through an http call in a webbrowser.

< ?php
//initialize the variables which we’ll use for the login test
$userid=$_GET[‘uid’];
$password=$_GET[‘pass’];

//this too can be a query string variable if you want to test the ftp accounts on a different server
$ftp_server = “localhost”;
$conn_id = ftp_connect($ftp_server) or die(“Couldn’t connect to $ftp_server”);

// Open a session to an external ftp site
$login_result = ftp_login ($conn_id, $userid, $password);

// Check open
if ((!$conn_id) || (!$login_result)) {
echo “Ftp-connect failed!”; die;
} else {
echo “Connected.”;
}

//most important clean up after you’re done!
ftp_close()

?>

The utility of this extremely simple script is more evident when you consider a PHP hosting setup where you dont really want to use a ftp client to test. There just calling the script with the variables pulled from a db is enough to test the validity of credentials.

This is a part of the proftpd+mysql writeup which I’ll post pretty soon

Leave a Reply

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