Re: grep with ftp
Dan Muey wrote: > > But the subject says grep? :) I see. It is a mailer problem. If you follow the thread you will see that this response was focused on Bob's comment concerning gep on file-names. I assumed here that the question concerned not the specific name of the function, but the logical effect--that of getting all matches to a regular expression within a specific domain. When the domain is filenames, i.e. when you seek all files of a given pattern, this logical function can be achieved using the ls method of the Net::FTP object. This capacity, as I said, is clearly not documented, yet it is there. Although I totally agree with Bob's point about grep'ing file contents, it really never occured to me that anyone would expect that capability. It is simply not one of the typical offerings of the FTP protocol. I would look for questions on that more in Net::Telnet, which was specifically designed for running processes on a remote machine. Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: grep with ftp
> > > > Johnson, Shaunn wrote: > > > > > Howdy: > > > > > > > > > > I'm looking for information that will let me > > > > > open an ftp connection and grep / search > > > > > for files and then FTP them back to me. > > > > > > > > What do you mean "grep/search" for files? If you want to search > > > > for particular file *names*, Net::FTP can return a list > of files > > > > and directories you can examine. > > > > > > True, but it is an inadequately documented feature of the > module. > > > The pod indicates only an optional DIR parameter for the ls > > > function: > > > > > > ls ( [ DIR ] ) > > > Get a directory listing of "DIR", or the current > directory. > > > > > > In an array context, returns a list of lines > returned from the > > > server. In a scalar context, returns a reference > to a list. > > > > > > But the following: > > > > > > my @files = $ftp->ls("*.jpg"); > > > > Since there is noe directory '*.jpg' it just does the ls on the cwd. > > Yeppers. > > > So DIR is a directory, /images for instance > > Nope. The directory being queried contains 50-100 files, of > all types. No no, /images was an example of what you might want to put there instead of trying regexes. For /home/ftpuser/public_html/images would be $ftp->ls("/public_html/images"); > > > > > It looks like you are trying to ls jpg files but this isn't > grep and > > the regex isn't even right, it looks more like a winders type thing. > > The directory is on a Linux web-server. > The OP was concerned with fileglobbing through the Net::FTP > ls function, not grep. But the subject says grep? :) So basically: you can ls a directory for list of files and you can then grep that array of filenames in your script but to actually grep()the contents of the files listed you'd have to: Ftp them to yout local file system or at least inside your script or you could use Telnet or ssh and run cat/grep commands on the file contents. But with FTP there is no way to look at the contents of the file without transfering the file to your script first. Maybe I could add a grep function to my Net::FTP helper functions in a module I may Do if I ever get time! > > Dan, it works. > > Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: grep with ftp
Dan Muey wrote: > > Bob Showalter wrote: > > > > > Johnson, Shaunn wrote: > > > > Howdy: > > > > > > > > I'm looking for information that will let me > > > > open an ftp connection and grep / search > > > > for files and then FTP them back to me. > > > > > > What do you mean "grep/search" for files? If you want to search for > > > particular file *names*, Net::FTP can return a list of files and > > > directories you can examine. > > > > True, but it is an inadequately documented feature of the > > module. The pod indicates only an optional DIR parameter for > > the ls function: > > > > ls ( [ DIR ] ) > > Get a directory listing of "DIR", or the current directory. > > > > In an array context, returns a list of lines returned from the > > server. In a scalar context, returns a reference to a list. > > > > But the following: > > > > my @files = $ftp->ls("*.jpg"); > > Since there is noe directory '*.jpg' it just does the ls on the cwd. Yeppers. > So DIR is a directory, /images for instance Nope. The directory being queried contains 50-100 files, of all types. > > It looks like you are trying to ls jpg files but this isn't grep and the regex isn't > even right, it looks more like a winders type thing. The directory is on a Linux web-server. The OP was concerned with fileglobbing through the Net::FTP ls function, not grep. Dan, it works. Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: grep with ftp
> Bob Showalter wrote: > > > Johnson, Shaunn wrote: > > > Howdy: > > > > > > I'm looking for information that will let me > > > open an ftp connection and grep / search > > > for files and then FTP them back to me. > > > > What do you mean "grep/search" for files? If you want to search for > > particular file *names*, Net::FTP can return a list of files and > > directories you can examine. > > True, but it is an inadequately documented feature of the > module. The pod indicates only an optional DIR parameter for > the ls function: > > ls ( [ DIR ] ) > Get a directory listing of "DIR", or the current directory. > > In an array context, returns a list of lines returned from the > server. In a scalar context, returns a reference to a list. > > But the following: > > my @files = $ftp->ls("*.jpg"); Since there is noe directory '*.jpg' it just does the ls on the cwd. So DIR is a directory, /images for instance It looks like you are trying to ls jpg files but this isn't grep and the regex isn't even right, it looks more like a winders type thing. Try this: my @jpgfiules = grep(/\.jpg$/, $ftp->ls("/images")); # / is the directory you ftp into like /home/foo, so you do /images for the directory /home/foo/images > print "$_\n" foreach @files; > > does render: Hmmm what is in the cwd if you ftp in via WS-FTP or somehting? > > Clouds.jpg > DarkSky.jpg > Davis Logo.jpg > DavisLogo.jpg > > Joseph HTH DMuey -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: grep with ftp
Bob Showalter wrote: > Johnson, Shaunn wrote: > > Howdy: > > > > I'm looking for information that will let me > > open an ftp connection and grep / search > > for files and then FTP them back to me. > > What do you mean "grep/search" for files? If you want to search for > particular file *names*, Net::FTP can return a list of files and directories > you can examine. True, but it is an inadequately documented feature of the module. The pod indicates only an optional DIR parameter for the ls function: ls ( [ DIR ] ) Get a directory listing of "DIR", or the current directory. In an array context, returns a list of lines returned from the server. In a scalar context, returns a reference to a list. But the following: my @files = $ftp->ls("*.jpg"); print "$_\n" foreach @files; does render: Clouds.jpg DarkSky.jpg Davis Logo.jpg DavisLogo.jpg Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: grep with ftp
> Howdy: Howdy > > I'm looking for information that will let me > open an ftp connection and grep / search > for files and then FTP them back to me. > Yout can use the ls function to get an array of file names in that folder and grep the names. Unless you have a unique ftp server on the remote server I know of no standard ftp commands to grep the contents of files while they are on the other server. So you can - grep the filename list - Get the file contents locally and search through their contents (probably too much trouble) You might look into Net::Telnet, then you can log on the the server and issue a grep/grep like command as if you were actually on the command line, ( Well err since you technically are) and then once said file is found ftp it to your server or do whatever. HTH DMuey > I saw something about FTP and macros, but > the other articles about Net::FTP got me to > believe you can do this with Perl. If so, > is Net::FTP the route the go? > > Is this possible? > > Thanks! > > -X > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: grep with ftp
Johnson, Shaunn wrote: > Howdy: > > I'm looking for information that will let me > open an ftp connection and grep / search > for files and then FTP them back to me. What do you mean "grep/search" for files? If you want to search for particular file *names*, Net::FTP can return a list of files and directories you can examine. If you want to search in the *contents* of files, you'll need to transfer the files to the client side first and then search through them. There's no way to get the FTP server to search for you, AFAIK. If this is what you're after, perhaps FTP isn't the right solution. You might consider ssh/scp if that's approriate for your environment. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: grep with ftp
On Aug 28, K Old said: >@filelist = grep{/[e|f][d|m|v|s].ic$/} $ftp->ls($path); You probably means @filelist = grep { /[ef][dmvs]\.ic$/ } $ftp->ls($path); since character classes don't use | for alternation, and . is a metacharacter in a regex. -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ what does y/// stand for? why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: grep with ftp
On Thu, 2003-08-28 at 10:34, Johnson, Shaunn wrote: > Howdy: > > I'm looking for information that will let me > open an ftp connection and grep / search > for files and then FTP them back to me. > > I saw something about FTP and macros, but > the other articles about Net::FTP got me to > believe you can do this with Perl. If so, > is Net::FTP the route the go? > > Is this possible? Of course it is! Here's a connection I use on our local network that greps for files using the output of $ftp->ls and the grep function. Then you throw them in a loop with $ftp->get() and your done. Yeah, sure more error checking can be done, but this serves my purpose. $ftp = Net::FTP->new("172.16.1.2", Debug=> 0); $ftp->login("usr4",'cam'); $ftp->ascii; $ftp->cwd($path); @filelist = grep{/[e|f][d|m|v|s].ic$/} $ftp->ls($path); foreach (@filelist) { print "$_\n"; $ftp->get($_) or warn "Net::FTP->get: couldn't get $_"; } #$ftp->get($file1); #$ftp->get($file2); $ftp->quit; Hope this helps, Kevin -- K Old <[EMAIL PROTECTED]> -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: grep with ftp
> Is this possible? I'm no expert of FTP software, so I can't say if that is generally possible, but it will depend on what the FTP server software allows you to do. So I would start there, find out what software they are running, then find some documentation on it. Rob -Original Message- From: Johnson, Shaunn [mailto:[EMAIL PROTECTED] Sent: Thursday, August 28, 2003 10:34 AM To: [EMAIL PROTECTED] Subject: grep with ftp Howdy: I'm looking for information that will let me open an ftp connection and grep / search for files and then FTP them back to me. I saw something about FTP and macros, but the other articles about Net::FTP got me to believe you can do this with Perl. If so, is Net::FTP the route the go? Is this possible? Thanks! -X -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]