use strict; use Net::FTP; my $ftp_user = 'anonymous'; my $ftp_pwd = 'anonymous'; my @FOLDERS = ('folder1' , 'folder2'); my @IPLIST = ('xxx.xxx.xxx.xxx'); my $TESTFILE = 'testfile.txt'; my @open_ips = checkips(\@FOLDERS, \@IPLIST, $TESTFILE, $ftp_user, $ftp_pwd); print join("\n", @open_ips); sub checkips { my ($ref_FOLDERS, $ref_IPLIST, $TESTFILE, $user, $pwd) = @_; my @OPENIPS; foreach my $CURRENTIP (@{$ref_IPLIST}) { print "Trying $CURRENTIP\n"; my $ftp = Net::FTP->new($CURRENTIP, Debug => 0) or ( print "Cannot connect to $CURRENTIP: $@" and next ); $ftp->login($user,"-$pwd\@") or ( print "Cannot login " , $ftp->message and next ); foreach my $CURRENTFOLDER (@{$ref_FOLDERS}) { print "* Now scanning $CURRENTIP with folder $CURRENTFOLDER:\n"; $ftp->cwd("/$CURRENTFOLDER") or ( print "Cannot change working directory to $CURRENTFOLDER: ", $ftp->message and next ); #print "PWD: " . $ftp->pwd . "\n"; $ftp->put("$TESTFILE") || ( print "Cannot put $TESTFILE to $CURRENTFOLDER: ", $ftp->message and next); push(@OPENIPS, "IP: $CURRENTIP with Folder: $CURRENTFOLDER"); print "\n\n"; } $ftp->quit(); } return @OPENIPS; }