Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

unlink files after ftp list

Status
Not open for further replies.

rozzay

Programmer
Jan 3, 2002
142
US
Morning,

I am trying to unlink(delete files) after ftp a list of files successfully to another server. I tried doing so when I receive a good return code for ftping the files
but receive an error message of "Can't return outside a subroutine at cyclone_ob_GIS_2.pl line 31." Your help is appreciated.

=========================================
#!/usr/bin/perl
# The files are moved in batch mode.

my $now=localtime;

open(LOG, ">>/usr/local/cyclone/logs");
$edioldtmp_dir = "test/ediold/tmp";

opendir(DIR, $edioldtmp_dir);
print "Open dir\n";
opendir(EDIOLDTMP, $edioldtmp_dir) or die "Can't open $dir: $!";
while ( defined ($file = readdir(DIR)) ) {
next if $file =~ /^\.\.?/;
}
use Net::FTP;
$mode = "ascii";

@files = glob("$edioldtmp_dir/*");

$ftp = Net::FTP->new("test.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->binary()if ($mode eq "binary");
$ftp ->put ($file) || return(1);
}
$ftp->quit() || return(1);
if (return == 0) {unlink ( $file@files),
print log "$now-> File: $file\n:"};

closedir(EDIOLDTMP);
closedir(DIR);
close LOG;
 
your script has a few errors and some parts of the code that are doing nothing. It looks like you may have copy and pasted the code from another script that was using a sub routine to do the FTP stuff. Otherwise all those return(1) functions are useless and explain the error message you are getting.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top