Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

(Dermot) Using Net::FTP, dir(), symlinks: are they files or directories?

by Dermot (Scribe)
on Dec 04, 2000 at 17:29 UTC ( #44781=perlquestion: print w/replies, xml ) Need Help??

Dermot has asked for the wisdom of the Perl Monks concerning the following question:

I am using Net::FTP to write some code that connects to an FTP site scans the directory structure and reports by email on files which have been updated since the last scan. When I do $ftp->dir() I then use a regex which searches for start-of-line followed by either a d or an l in order to separate the directories from the files. This is so I can scan directories and check files. My problem is that files which are symbolic links (lrwxr-xr-x in the dir output) could point to either files or directories. My workaround, which I am not too happy with, is to first assume that they are directories and $ftp->cwd() into the directory checking return codes as I go. When there has been an error I then know that the link was not pointing to a directory but a file so I put it on the file list instead.

Any advice? Am I reinventing the wheel? Are their flaws in my workaround?

  • Comment on (Dermot) Using Net::FTP, dir(), symlinks: are they files or directories?

Replies are listed 'Best First'.
Re: (Dermot) Using Net::FTP, dir(), symlinks: are they files or directories?
by repson (Chaplain) on Dec 04, 2000 at 18:18 UTC
    This workaround does seem dodgey to me. I did a bit of looking around and this is what I found.

    First stop the Net::FTP docs. Nothing helpful there except a few commands I don't recognise.

    Next stop the RFC Net::FTP says it was based on at IETF. Then test the information I found.

    The command $ftp->list(filename) returns (on my linux system) the same symbolic link `ls` type information for a file AND the dereferenced directory in the case of a directory.

    So if the returned starts with a 'd', the link points to a directory and otherwise not (I think).

    Note: $ftp->list(filename) returns a glob, so you'll have to read from it like a filehandle.

    Hope that points you in a better direction....

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://44781]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2020-10-22 18:43 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (229 votes). Check out past polls.