Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Net::FTP and "mput" issue...cannot change local currently directory

Reply
Thread Tools

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

 
 
John Davis
Guest
Posts: n/a
 
      01-30-2004
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;
 
Reply With Quote
 
 
 
 
Sisyphus
Guest
Posts: n/a
 
      01-31-2004
John Davis wrote:

> ---------------------
>
>
> #!/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


--
To reply by email u have to take out the u in kalinaubears.

 
Reply With Quote
 
 
 
 
Ben Morrow
Guest
Posts: n/a
 
      01-31-2004

Sisyphus <(E-Mail Removed)> wrote:
> #'.' 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

--
We do not stop playing because we grow old;
we grow old because we stop playing.
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
John Davis
Guest
Posts: n/a
 
      02-02-2004
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!

Ben Morrow <(E-Mail Removed)> wrote in message news:<bvfjlj$1hg$(E-Mail Removed)>...
> Sisyphus <(E-Mail Removed)> wrote:
> > #'.' 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

 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      02-02-2004
John Davis <(E-Mail Removed)> wrote:

> 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]

--
Tad McClellan SGML consulting
(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to find directory of currently running .rb file Kenneth McDonald Ruby 1 10-27-2008 09:18 PM
System.IO.Directory.GetDirectories() and System.IO.Directory.GetFiles() are not returning the specified directory Nathan Sokalski ASP .Net 2 09-06-2007 03:58 PM
How do you get a list of files currently in a directory?? Rob_S C++ 2 03-01-2006 12:58 PM
"Directory Service is currently unavailable" =?Utf-8?B?U3VzaWUtUQ==?= Windows 64bit 3 12-16-2005 09:36 PM
User Currently logged on to the local system Aqua Perl Misc 0 07-06-2004 12:28 PM



Advertisments