Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

lcd in Net::FTP module

by gopalr (Priest)
on Aug 04, 2009 at 07:01 UTC ( [id://785663] : perlquestion . print w/replies, xml ) Need Help??

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

We are using the following to change remote directory


Please guide me, how to change local directory. I used $ftp->lcd($local_directory), but is showing an error message Can't locate object method "lcd" via package "Net::FTP" at line 82.

Please guide me. Thanks in Advance!!


Replies are listed 'Best First'.
Re: lcd in Net::FTP module
by derby (Abbot) on Aug 04, 2009 at 11:04 UTC

    While lcd makes sense when you're in an interactive FTP session, you really don't need it when scripting (at least with perl) -- use the built-in chdir function:

    use Net::FTP; my $ftp = Net::FTP->new("", Debug => 0) or die "Cannot connect to $@"; $ftp->login("anonymous",'-anonymous@') or die "Cannot login ", $ftp->message; $ftp->cwd("/pub") or die "Cannot change working directory ", $ftp->message; chdir "/tmp" or die "Cannot change local directory ", $!; $ftp->get("that.file") or die "get failed ", $ftp->message; $ftp->quit;
    (modified from the example at Net::FTP).
Re: lcd in Net::FTP module
by Anonymous Monk on Aug 04, 2009 at 08:01 UTC
Re: lcd in Net::FTP module
by Khen1950fx (Canon) on Aug 04, 2009 at 08:56 UTC
    If you were using straight ftp, then you would use cd to change directory on the remote, and you would use lcd to change the local directory. However, there is no cd or lcd in Net::FTP, at least none that I can find. The "cwd" command should work for both remote and local directories.
Re: lcd in Net::FTP module
by Selvakumar (Scribe) on Aug 04, 2009 at 11:26 UTC
    Net::FTP to process ftp and explain more details about the requirement of change local directly to get exact answer. opendir cammand to read all the files from your local directory.