Net::FTP and "mput" issue...cannot change local currently directory

J

John Davis

I'm trying to use the Net::FTP module in an "mput" like way, but it
does not seem to work correctly. I have a script that gets any number
of files from another server and put them in a directory called
"/tmp/dbinfo"

From /tmp/dinfo, I want to mput all of those files that are in the
directory with the db.out attached to the name, and only those files.
So files such as acedb.out, testdb,out are good, etc.

From my code below, it continues to say that files such as acedb.out,
testdb.out cannot be accessed. If that because the local currently
directory is not set right? I have a chdir (/tmp/dbinfo) - where the
files are, but it cannot put them onto the remote host.

I've moved the chdir around but without success...

Any ideas?

Thanks!


---------------------


#!/opt/perl/bin/perl -w

use strict;
use Net::FTP;
my ($hostname, $username, $password, $directory, $ftp, @last);
$hostname="dbmaster1";
$username="ftp";
$password="nothing";
$directory="/incoming";

my @filelist;
my $file;

chdir ("/tmp/dbinfo");

opendir (DIR, "/tmp/dbinfo") || die "Can't open: $! \n";
@filelist=readdir(DIR);
closedir(DIR);

$ftp=Net::FTP->new ($hostname);
$ftp->login($username, $password);
$ftp->cwd ($directory);

foreach $file (@filelist) {
next if ! ($file=~/db.out/) ;
$ftp->put("$file");
}
$ftp->quit;
 
S

Sisyphus

John said:
---------------------


#!/opt/perl/bin/perl -w

use strict;
use Net::FTP

use Cwd;
my ($hostname, $username, $password, $directory, $ftp, @last);
$hostname="dbmaster1";
$username="ftp";
$password="nothing";
$directory="/incoming";

# It might not matter but I would have expected:
$directory = "incoming";

my @filelist;
my $file;

chdir ("/tmp/dbinfo");

# Check that you're where you think you are:
print "Current directory is: ", getcwd(), "\n";
opendir (DIR, "/tmp/dbinfo") || die "Can't open: $! \n";
@filelist=readdir(DIR);
closedir(DIR);

$ftp=Net::FTP->new ($hostname);
$ftp->login($username, $password);
$ftp->cwd ($directory);

foreach $file (@filelist) {
next if ! ($file=~/db.out/) ;

#'.' has special significance in regex. I think you want:
next if ! ($file=~/db\.out/) ;
$ftp->put("$file");
}
$ftp->quit;

Hth.

Cheers,
Rob
 
B

Ben Morrow

Sisyphus said:
#'.' has special significance in regex. I think you want:
next if ! ($file=~/db\.out/) ;

And *I* think you want

next if $file !~ /db\.out$/;

or

next unless $file =~ /db\.out$/;

Ben
 
J

John Davis

Hmm..thanks for the replies folks.

I think the last thing is, I cannot seem to do an "lcd" like when you
do that from the ftp prompt. I am trying to emulate "lcd /tmp/dbinfo".

The cwd module helped me to see that I was still in the current
directory where and I run my script "~/bin"), but I want to go to
/tmp/dbinfo. It seems my

chdir (/tmp/dbinfo);

is ignored. Printing out the cwd still says "~/bin" - no matter
what....

How do I go about getting into that directory (on my local box),
because it's there that I want to "mput" my files.

Thanks guys!
 
T

Tad McClellan

John Davis said:
It seems my

chdir (/tmp/dbinfo);


That is not Perl code, it will not compile.

You should put quotes around strings.

is ignored.


Then you should ask perl to tell you _why_ it failed by
checking the return value and showing the contents of $! :


chdir '/tmp/dbinfo' or die "could not cd to '/tmp/dbinfo' $!";



[snip TOFU. Please do not post upside-down like that]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top