Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: ftp files from Unix m/c

by amphiplex (Monk)
on Jul 22, 2002 at 09:44 UTC ( [id://183993]=note: print w/replies, xml ) Need Help??


in reply to ftp files from Unix m/c

Hi !

The simplest method would be to use the cwd method to change the current directory to the one you want to do an ls in.

BTW: Answers here are generally posted here as a reply node, so that others can see if a question was answered already, correct answers or learn from them.

Update: Here is some code that might help you:
use strict; use Net::FTP; my $remote_host = "*****************"; my $remote_user = "*******"; my $remote_password = "*******"; my $remote_dir = "/tmp"; my $ftp = Net::FTP->new($remote_host) or die "error initiating ftp: $! +\n"; $ftp->login($remote_user,$remote_password) or die "couldn't login: $!\ +n"; # force binary transmission of files, generally a good idea $ftp->binary(); my @files = $ftp->ls($remote_dir); print join "\n",@files; print "\n","="x80,"\n"; # now change current working directory and do ls there $ftp->cwd($remote_dir); my @files = $ftp->ls(); print join "\n",@files;

---- amphiplex

Replies are listed 'Best First'.
Re: Re: ftp files from Unix m/c
by simeon2000 (Monk) on Jul 22, 2002 at 13:21 UTC
    I think what the person is asking is how to do a listing, but ignore all of the directory entries in the directory he is reading from.

    Frankly, I don't think this could be done with Net::FTP->ls(), AFAIK, because it doesn't give you any bits to determine between dirs and files, and you certainly can't do a grep ! -d  $_, readdir REMOTE_DIR with the FTP module.

    Perhaps the easiest way would be to use the Net::FTP->dir command. This will give you an ls -l UNIX long directory list with file permissions and stuff. Then you can probably do a  grep ! /^d/, Net::FTP->dir() instead. Of course, then you have to extract the filename from each line from amidst the other info, but that's not hard.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://183993]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2025-01-18 07:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which URL do you most often use to access this site?












    Results (56 votes). Check out past polls.