use Fcntl ':mode'; my $mode = ...; if (S_ISDIR($mode)) { # directory ... } elsif (S_ISLNK($mode)) { # link ... } elsif (... #### use Net::SFTP::Foreign; my $sftp = Net::SFTP::Foreign->new($host); $sftp->error and die "unable to connect to remote host: ".$sftp->error; $sftp->rget($remote_dir, $local_dir);