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!

ftp multiple files in single session

Status
Not open for further replies.

rozzay

Programmer
Jan 3, 2002
142
US
Morning,

Is perl able to ftp multiple files in a single session. Currently I have a perl script that ftps the file to another server but it does one at a time open/closing a session which the 2nd server is unable to handle. Thanks in advance.
======================================================
opendir(DIR, $edioldtmp_dir);
while ( defined($file = readdir(DIR)) ) {
next if $file =~ /^\.\.?/;
$ftpsub_rc=ftpsub();
if ( $ftpsub_rc == 0 ) { unlink( $edioldtmp_dir . "/" . $file),
print LOG "$now->File: $file\n" };
}
};

sub ftpsub {
use Net::FTP;
my $ftp;
$ftp = Net::FTP->new("sample.com", Port => 21, Debug => 1) || return(1);
$ftp->login("loginid", "password") || return(1);
$ftp->cwd ("INBOUND/EDI") || return(1);
$ftp ->put ($edioldtmp_dir . "/" . $file) || return(1);
$ftp->quit() || return(1);
return (0);
};
 
one thought would be to shell the ftp command with a settings file?

The tidyup and all that could be troublesome though

Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
The problem seems to be that the script is running all of the FTP actions in a single sub. So, every time it finds a file that needs FTPed, it connects to the server, FTPs th file, then disconnects. You could clean up the code and speed up the script if you connected to the FTP server before reading your directories, and closed after everything's been processed.

- George
 
Ok sounds good below I try to ftp the files but instead of processing i am ftp a list of files but I receive an error message of pathname does not exist. Sorry I am really green in pearl
==================================================
#!/usr/bin/perl
my $now=localtime;

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

opendir(DIR, $edioldtmp_dir);
print "Open dir\n";
opendir(EDIOLDTMP, $edioldtmp_dir) or die "Can't open $dir: $!";

use Net::FTP;
$mode = "binary";
@files = qw($ediold_tmp);

$ftp = Net::FTP->new("sample.com", Port => 21, Debug => 1) || return(1);
$ftp->login("login", "password") || return(1);
$ftp->cwd ("/INBOUND/EDI") || return(1);
foreach $f(@files)
{
$ftp->ascii() if($mode eq "ascii");
$ftp->binary()if ($mode eq "binary");
$ftp ->put ($f) || return(1);
}
$ftp->quit() || return(1);
return (0);

closedir(EDIOLDTMP);
closedir(DIR);

close LOG;

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top