Hello i am trying to ftp a list of files in a single session once done ftp the files successfully i would like to delete the list files. Instead of deleting the files are ftp twice and then error message of "Can't return outside a subroutine" at the line of closedir(EDIOLDTMP)
#!/usr/bin/perl
# The files are moved in batch mode.
my $now=localtime;
open(LOG, ">>/local/logs");
$edioldtmp_dir = "/local/ediold/tmp";
opendir(DIR, $edioldtmp_dir);
opendir(EDIOLDTMP, $edioldtmp_dir) or die "Can't open $dir: $!";
while ( defined ($file = readdir(DIR)) )
{
next if $file =~ /^\.\.?/;
@files = glob("$edioldtmp_dir/*");
$ftpsub_rc=ftpsub();
print "return code= $ftpsub_rc\n";
if ( $ftpsub_rc == 0 )
{
unlink( $edioldtmp_dir . "/" . $file),
print LOG "$now-> File: $file\n:" };
print "$file\n";
print "files deleting\n";
};
sub ftpsub
{
use Net::FTP;
$mode = "ascii";
my $ftp;
$ftp = Net::FTP->new("sample.com", Port => 21, Debug => 1) || return(1);
$ftp->login("userid", "password") || return(1);
$ftp->cwd ("/INBOUND/EDI") || return(1);
foreach $file(@files)
{
$ftp->ascii() if($mode eq "ascii");
$ftp ->put ($file) || return(1);
}
};
return (0);
$ftp->quit() || return(1);
closedir(EDIOLDTMP);
closedir(DIR);
close LOG;
#!/usr/bin/perl
# The files are moved in batch mode.
my $now=localtime;
open(LOG, ">>/local/logs");
$edioldtmp_dir = "/local/ediold/tmp";
opendir(DIR, $edioldtmp_dir);
opendir(EDIOLDTMP, $edioldtmp_dir) or die "Can't open $dir: $!";
while ( defined ($file = readdir(DIR)) )
{
next if $file =~ /^\.\.?/;
@files = glob("$edioldtmp_dir/*");
$ftpsub_rc=ftpsub();
print "return code= $ftpsub_rc\n";
if ( $ftpsub_rc == 0 )
{
unlink( $edioldtmp_dir . "/" . $file),
print LOG "$now-> File: $file\n:" };
print "$file\n";
print "files deleting\n";
};
sub ftpsub
{
use Net::FTP;
$mode = "ascii";
my $ftp;
$ftp = Net::FTP->new("sample.com", Port => 21, Debug => 1) || return(1);
$ftp->login("userid", "password") || return(1);
$ftp->cwd ("/INBOUND/EDI") || return(1);
foreach $file(@files)
{
$ftp->ascii() if($mode eq "ascii");
$ftp ->put ($file) || return(1);
}
};
return (0);
$ftp->quit() || return(1);
closedir(EDIOLDTMP);
closedir(DIR);
close LOG;