Rajib,
I think your mistake is that you don't use an array for the directory
results. Here a piece of code I'm using to do something similar, I changed
it a little bit to better point out the parts you need, so there is maybe a
typo here and there, I'm sure you will figure it out and should be a ble to
get the idea.
sub get_confirmationfiles{
my (@allfiles, $file, $h_ftp, $n);
my $test;
$h_ftp = Net::FTP->new($host1_name, Debug => 0);
$h_ftp->login($host1_account,$host1_pwd);
if ($host1_path ne "nopath")) {
$h_ftp->cwd($host1_path);
}
# check if there are files in the directory
@allfiles = $h_ftp->ls();
$n = @allfiles
if ($n == 0) {
print "No files for download on $host1_name";
exit 0;
}
# selcect files which meet the searchstring
foreach $file (@allfiles) {
if ($file =~ /$host1_filematch/i)
{push(@confirmationfiles_pgp, $file)}
}
$n = @confirmationfiles_pgp
if ($n == 0) {
print "No files for download on $host1_name";
exit 0;
}
#download confirmation files
foreach $file (@confirmationfiles_pgp) {
$h_ftp->get($file);
print "$file downloaded from $host1";
}
$h_ftp->quit;
}
-----Original Message-----
From: Sengupta, Rajib (CC-Contractor)
[mailto:[EMAIL PROTECTED]]
Sent: Wednesday, April 24, 2002 5:47 PM
To: 'Jenda Krynicky'; [EMAIL PROTECTED]
Subject: RE: Want help for FTP using Perl
Thanks Jenda.
while trying it I am stuck again(though i am sure it is a trivial one for
you people):
first i am just trying to get the file name from a folder..
i am having a directory in C:/Perl/allperl/Testftp and inside this testftp
directory my test file is residing which is test.txt.
My perli script is in C:/Perl/allperl/ftp.pl
the code i had put is:
#!/bin/perl -w
opendir(DIR, Testftp) || die "can't opendir $!";;
$filnam = readdir(DIR);
print $filnam
closedir DIR;
I am just trying to get the file name test.txt in the variable filnam.
This is causing me a problem as
print<> on unopened filehandle 0 at ftp.pl
I think i am doing something wrong in using readdir and assigning it to
$filnam. Can you help me please?
Thanks,
Rajib Sengupta
ConAgra Business Systems
Peoplesoft AR and Order Management
222 South 15th St,North Tower(CT-930)
Omaha NE 68102
Phone: (402) 595-7928,Fax: (402) 595-7024
-----Original Message-----
From: Jenda Krynicky [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, April 24, 2002 2:37 PM
To: [EMAIL PROTECTED]
Subject: Re: Want help for FTP using Perl
From: "Sengupta, Rajib \(CC-Contractor\)" <[EMAIL PROTECTED]>
>
> I am very new to unix as well as in perl. I had got a assignment in
> which I think perl will be the best bet. I am trying to accomplish the
> following:
> <sniped>
I'll reply by pointers to documentation.
If I say
perldoc -f whatever
run that command in the shell (command prompt).
> The steps are
>
> reading whatever file(there will be one file only ) is existing in a
> particuler folder and getting it's file name- i am not sure can we do
> this by perl,.i.e trying to get a file name from a folder..
> store the
> file name in a variable
perldoc -f opendir
perldoc -f readdir
perldoc -f closedir
or
perldoc -f glob
> getting current time stamp
perldoc -f time
> creating a new file name
perldoc -f rename
You should probably move the file to a different directory at this
point to make sure the ca-unicenter will not be triggered again.
> executing ftp commands in perl script by using the variable
names
> to put it to another server.
perldoc Net::FTP
Net::FTP's docs contain exaamples, the other things should be
trivial.
There is one problem though. I do not know if ca-unicenter can do
this for you, but you should only start renaming and FTPing the file
unce it is complete.
Jenda
=========== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ==========
There is a reason for living. There must be. I've seen it somewhere.
It's just that in the mess on my table ... and in my brain
I can't find it.
--- me
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs