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

Discussion in 'Perl Misc' started by John Davis, Jan 30, 2004.

  1. John Davis

    John Davis Guest

    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;
     
    John Davis, Jan 30, 2004
    #1
    1. Advertising

  2. John Davis

    Sisyphus Guest

    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.
     
    Sisyphus, Jan 31, 2004
    #2
    1. Advertising

  3. John Davis

    Ben Morrow Guest

    Sisyphus <> 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.
     
    Ben Morrow, Jan 31, 2004
    #3
  4. John Davis

    John Davis Guest

    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 <> wrote in message news:<bvfjlj$1hg$>...
    > Sisyphus <> 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
     
    John Davis, Feb 2, 2004
    #4
  5. John Davis <> 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
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Feb 2, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. alex goretoy
    Replies:
    0
    Views:
    467
    alex goretoy
    Jan 15, 2009
  2. alex goretoy
    Replies:
    0
    Views:
    522
    alex goretoy
    Jan 15, 2009
  3. D. Buck
    Replies:
    2
    Views:
    493
    D. Buck
    Jun 29, 2004
  4. Aqua
    Replies:
    0
    Views:
    101
  5. blackdog

    $ftp->??? for changing local directory

    blackdog, Jan 6, 2006, in forum: Perl Misc
    Replies:
    4
    Views:
    657
    Gunnar Hjalmarsson
    Jan 9, 2006
Loading...

Share This Page