By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,889 Members | 1,044 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,889 IT Pros & Developers. It's quick & easy.

HOWTO: Check FTP Site Is Up

P: n/a
Had to write something similar to this for my office. You can adapt to
your use. I just put it on a chron job for every 15 minutes. My bash
script did:

#!/bin/bash
php -d max_execution_time=1000 -q /root/projects/ftptest/ftptester.php

<?php
// ftptester.php:

// use your own mail script -- see my note on this below
require('_sendmail.php');

$FTP_ADDR = 'myftpsite.com';
$FTP_USER = 'special';
$FTP_PASS = 'GhX77ED011FJH';
$FTP_TEST_FILE = 'ftptest.txt';
$FTP_TEST_FILE_PATH = '/root/projects/ftptest';
$SMTP_IP_ADDR = 'mymailserver.com';
$FROM = 'm*@me.com';
$TO = 't*@to.com';
$CC = 'c*@cc.com';
$SUBJECT = 'ALERT: FTP Server Unavailable!';
$MESSAGE = "\n********\n*** ALERT\n\nFTP server $FTP_ADDR is not
responding to file uploads.";
echo "\n\nStarting FTP Server Test...\n";
echo "\t...connecting to $FTP_ADDR\n";
$FTP = ftp_connect($FTP_ADDR);
echo "\t...login with special account\n";
ftp_login($FTP, $FTP_USER, $FTP_PASS);
echo "\t...waiting for latent FTP login\n";
sleep(4);
echo "\t...pushing test file\n";
ftp_put($FTP, $FTP_TEST_FILE, $FTP_TEST_FILE_PATH . '/' .
$FTP_TEST_FILE, FTP_ASCII);
echo "\t...waiting for latest FTP file upload\n";
sleep(4);
echo "\t...checking for file upload success\n";
$nSize = 0;
$nSize = @ ftp_size($FTP, $FTP_TEST_FILE);
if ($nSize < 1) {
echo "\t...PROBLEM! file upload failure\n";
// I don't want to plagarize, so use your own mail script, which
you can
// get easily from PHP.NET website if you search on fputs function
and
// scroll down to see user submitted entries
$mail->Send($SMTP_IP_ADDR, $FROM, $TO, $CC, $SUBJECT, $MESSAGE);
} else {
echo "\t...file upload was a SUCCESS\n";
}
echo "\t...deleting test file\n";
@ ftp_delete($FTP, $FTP_TEST_FILE);
sleep(1);
echo "\t...logging out\n";
ftp_quit($FTP);
echo "Stopped FTP Server Test\n\n";
?>
Jul 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.