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

I'm trying to do transfer some files via Net::Ftp but I'm having problems with the symbolic links. The main problems resides in the $ftp->cwd(), looks like the $ftp doesn't see the symbolic links in he directory. If I use $ftp->ls(), it will only give me directories whereas when using $ftp->dir(), all of the contents of the directory (dirs and symlinks will be shown). The ide is to check if there is a symlink and when that happens follow the link and start the transfer or if its a directory simply change to that directory and transfer, here's the code I'm using when doing the transfer:
$ftp = Net::FTP::Recursive->new($config{'host'}, isSymlink => 1, Debug + => 1); $ftp->login( $config{'user'}, $config{'pass'}); $ftp->cwd( $config{'trgt'}); my @listClients = $ftp->dir(); foreach $x (@listClients){ if (-l $x){ print "Inside link test ".$x."\n"; if (defined($clientLink = readlink($ftp->pwd()."/".$x))) { print "\t\t".$clientLink."\n"; $ftp-> cwd( $clientLink ); print $ftp->pwd(); } } else { $ftp->cwd( $client ); } } $ftp->binary(); $ftp->rput(); $ftp->quit;

2006-07-18 Retitled by Corion, as per Monastery guidelines
Original title: 'net::ftp'

Replies are listed 'Best First'.
Re: transfering symlinks with Net::FTP
by sgifford (Prior) on Jul 18, 2006 at 03:16 UTC
    Hi innuendo98,

    It looks to me like your problem is confusing local filesystem operations with remote ones. When you use the -l operator and readlink, it's looking in the local filesystem, not on the FTP server.

    I don't think there's a standard way to determine whether a remote file is a symlink or not. You can use $ftp->dir and try to parse the output, or see if the FTP server you're using supports any nonstandard extensions that allow this (try sending a HELP command).