------------------------------------------------ On Thu, 10 Jul 2003 21:56:17 +0100, "Rob Dixon" <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote: > > ----- Original Message ----- > > From: Rob Dixon <[EMAIL PROTECTED]> > > Date: Thursday, July 10, 2003 11:36 am > > Subject: Re: Net::FTP > > > > > Dan Muey wrote: > > > > > > What I'd like to do is simply: > > > > > > (WHERE exists() is hopefully a solution to my first > > > > > > question) > > > > > > > > > > > > if($ftp->exists($file)) { > > > > > > $ftp->delete($file); > > > > > > if($ftp->exists($file)) { print "Could not delete $file"; } > > > > > > else { print "$file is all gone"; } } else { print "$file > > > > > > does > > > > > not exist so > > > > > > I did not even try to delete it" } > > > > > > > > > > 'size' is the way to do it, but remember that it will return > > > > > zero for a file of zero size. What you need is 'defined'. > > > > > > > > > > This little subroutine will fulfil your wishes and make the > > > > > code above work. > > > > > > > > > > sub Net::FTP::exists { > > > > > my $ftp = shift; > > > > > defined $ftp->size(@_); > > > > > } > > > > > > > > > > HTH, > > > > > > > > As always Rob a huge help. I'll play around with that. > > > > It's makes so much sense when you think about it! > > > > I'll tuck that one away under my big hat too! > > > > > > > > > > Glad to help. FTP's a pain: as far as I know there's no way > > > of telling whether a filename is a plain file or a directory > > > either, without either trying to 'cwd' to it or parsing the > > > output or 'dir'. > > you probebly can tell if its a directory. just grab the first 1024 > > bytes, and look inside it. Will be eassy if its laying on top of > > UFS or FFS > > That depends on your file system. I don't think > most would let you open a directory as a plain file. > > What I'm pining for is something like > > $ftp->stat('entity'); > > Dan will tell us when he's written it :) > Which was going to be my question when Dan started talking about it, I think it would be cool to have, but what is being talked about being implemented is really outside of the Net::FTP scope since a) it isn't part of the FTP RFC, and 2) the reason it isn't is probably because of the wide range of FTP implementations. The phrase "That depends on the file system" depends on there being a file system to begin with, which is really my point, what about FTP servers on systems without the notions of directories, or even files, aka they deal with data sets and are line rather than file based. All of a sudden you need some way of marking the system type in the FTP connection object such that calling a 'stat' on a data set doesn't tell you the wrong information (or worse throws an exception, though they can be caught so maybe that is the best solution) for a system that isn't file based, etc. but to the best of my knowledge there is no way to deduce that from the FTP server's responses (at least not a standard way). I am certainly not an expert on those types of systems so that doesn't mean there isn't a way, but I know it is easy to get caught up in the file system notion because most widely used OS'es depend on one (I myself am young enough to have already had this happen) that building on top of something that is not RFC compliant can lead to issues. Any of the older gurus in the crowd that have dealt with line based FTP servers wish to comment? http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]