#!/usr/local/bin/perl #A very rudimentry ftp script for safetp #Dosent do any sanity checking around the transmitting of the file #Just shows how to acomplish the transfer #Butcher at will. No responsibility is held by author #Arran Price arran@paradise.net.nz 25/7/2000 use Expect; $Expect::Exp_Internal=1; $PROG="sftpc"; $PASS="user_password"; $USER="username"; $HOST="ftp_host_ip"; $FILENAME="testfile"; #the file we are putting - make sure it exists! $LOG="logfile"; #just a logfile you can use for helping debug $D=0; #Debug switch 0=off, 1=on #Pauses, helps troubleshooting when theres lots of stuff flooding the screen sub PAUSE { print"===>Hit enter to continue"; $PAUSE=; } #Prints Useful? debugging messages sub DEBUG { if ($D==1) { print"DEBUG === $_[0]\n"; LOG("$_[0]"); PAUSE; } } #Puts messages in the logfile sub LOG { DEBUG("$_[0]"); open(LF,">>$LOG") ||die "Cannot open Logfile $LOG for appending"; print LF "$_[0]"; close LF; } #What we do when we get a failure sub FAILED { DEBUG("$_[0]"); LOG("$_[0]"); exit; } sub MAIN { $ftp=Expect->spawn($PROG, $HOST) || FAILED "Couldnt create ftp instance.\n"; $ftp->expect(30,'User name')|| FAILED "Never got a username prompt\n"; DEBUG("Found username prompt. Entering username.\n"); print $ftp "$USER\r"; DEBUG("Username has been presented.\n"); sleep 5; $ftp->expect(30,'word:')|| FAILED "never got a password prompt\n"; DEBUG("Found password prompt. Entering password.\n"); print $ftp "$PASS\r"; DEBUG("Password has been presented.\n"); $ftp->expect(30,">") || FAILED "Never got a prompt\n"; DEBUG("Found the log in prompt, so putting a file.\n"); print $ftp "put testfile\r"; DEBUG("Testfile has been put, so now quitting.\n"); print $ftp "quit\r"; } #MAIN PROGRAM BLOCK MAIN;