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

Hi

I'm trying to get a list of files from an an FTP server. I'm using "cwd" to change to each directory on the server to get it's contents (using "ls"). The problem is I've just encountered an FTP server which supports a "cd" command, but not a "cwd" command.

Is there any way to get around this using Net::Ftp or some other module? Or is it possible to configure an FTP site to allow me to use the "cwd" command?

thanks,
A

Replies are listed 'Best First'.
Re: Net::FTP cd vs cwd
by steves (Curate) on Sep 20, 2004 at 10:59 UTC

    cwd is the Net::FTP method name; cd is the standard FTP and shell command for changing directories. You may be confusing the two. The question is what your FTP server does when you call Net::FTP's cwd method.

    I built a directory/file browser package on top of FTP and have run it across a variety of FTP servers. I have never found any that don't support Net::FTP's cwd method. I have found that I need to configure whether the ls or dir method is used to get long directory listings.

Re: Net::FTP cd vs cwd
by rupesh (Hermit) on Sep 20, 2004 at 11:49 UTC

    A small code to change the directory, display messages and output the current working directory.
    use strict; use Net::FTP; my ($ftp, $ftpmessage, $fullpath); { $ftp = Net::FTP->new(<ftphost>) or die "Error: $!"; $ftp->login(<ftpuser>, <ftppass>) or die "Login Failure: $!"; $ftp->binary(); $ftp->cwd("$directory") or die "Couldn't change directory. $!"; $ftpmessage=$ftp->message(); $fullpath=$ftp->pwd(); print "Fullpathname $fullpath\n"; }

    Rupesh.
      Thanks for the help - I hadn't noticed the "message" method before.

      I got my code working - the "cwd" was in fact successful (as revealed by a $ftp_con->message, and the problem lay elsewhere with a splice.

      Thanks,
      A