[Gllug] Something Simple

Dean dean.wilson3 at virgin.net
Wed Oct 31 16:49:32 UTC 2001


On Wed, Oct 31, 2001 at 03:12:15PM +0000, James Bailey wrote:
> I want to write some sort of script that I run and it connect to the ftp 
> server and then copies the contents of a directory up then disconnects..

Heres a simple one, if you need it to do anything else let me know[0]. I've
written half a dozen of these this week so its pretty much from memory.

	Dean
[0] If it can't upload it does no diagnose. You have to work out why. This
is for free you know ;)
-- 
Profanity is the one language all programmers understand
   --- Anon
-------------- next part --------------
#! /usr/bin/perl -w
use strict;
use warnings;
use Net::FTP;

my $Host = "10.10.0.";
my $User = "";
my $Pass = "";
my $SrcDir = "/home/dwilson/Play/MiscPerl/";

die "Source directory not found" unless -d $SrcDir;
die "Config not correct in $0" unless $Host && $User && $Pass;

opendir(SRC, $SrcDir) || die "Failed to open dir because of $!\n";
my @Files = readdir SRC;
closedir SRC;

my $FTPSess = Net::FTP->new($Host, Timeout => 35);

unless ($FTPSess) {
  die localtime() . ": Failed to connect via FTP to $Host\n";
}

my $Ret = $FTPSess->login($User, $Pass);

unless ($Ret) {
  die localtime() . ": Failed to login to $Host\n";
}

foreach my $File (@Files) {
  my $Ret;
  if (-f "$SrcDir/$File") {
    $Ret = $FTPSess->put($File);
  }
  unless ($Ret) {
    warn "Failed to upload $File";
	next;
  }	
} 

$FTPSess->quit;


More information about the GLLUG mailing list