HOWTO: Check FTP Site Is Up

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

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:

php -d max_execution_time=1000 -q /root/projects/ftptest/ftptester.php

// ftptester.php:

  // use your own mail script -- see my note on this below

  $FTP_ADDR = '';
  $FTP_USER = 'special';
  $FTP_PASS = 'GhX77ED011FJH';
  $FTP_TEST_FILE = 'ftptest.txt';
  $FTP_TEST_FILE_PATH = '/root/projects/ftptest';
  $SMTP_IP_ADDR = '';
  $FROM = '';
  $TO = '';
  $CC = '';
  $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";
  echo "\t...pushing test file\n";
  ftp_put($FTP, $FTP_TEST_FILE, $FTP_TEST_FILE_PATH . '/' .
  echo "\t...waiting for latest FTP file upload\n";
  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
    // 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);
  echo "\t...logging out\n";
  echo "Stopped FTP Server Test\n\n";

Site Timeline