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

hi to Perlmonks
use Net::SFTP; my $sftp = Net::SFTP->new($host,(user => $user, password => $password, +) ,debug=>1); $sftp->get("dir/Net-SSH-Perl-1.30","Net-SSH-Perl-1.30");

Net-SSH-Perl-1.30 copying from Remote host.
But not giving like directory
.it is writing all the file in that diretory as one file.
wht i have given syntax wrong?

Replies are listed 'Best First'.
Re: how copy dir in NET::SFTP
by jdtoronto (Prior) on Jul 09, 2006 at 13:06 UTC
Re: how copy dir in NET::SFTP
by shmem (Chancellor) on Jul 09, 2006 at 12:16 UTC
    According to the documentation in Net::SFTP get does transfer a file, not a directory.

    Transfer of a directory is done by making a local directory , chdir there, and get the files one by one from the remote directory.

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re: how copy dir in NET::SFTP
by zentara (Cardinal) on Jul 09, 2006 at 12:17 UTC
    This might help you -> SFTP Sync

    I will tell you that SFTP is VERY finicky about filenames, paths, and full filenames (must be the fullpath to the file, NOT relative paths).


    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
Re: how copy dir in NET::SFTP
by stonecolddevin (Parson) on Jul 09, 2006 at 21:43 UTC

    I think you need to keep in mind that Net::SFTP and other such FTP modules are designed after FTP functions themselves, therefore the idea is to make it like you're giving the commands, just from a program, not a command line.

    A solution would be to compare it to what it would take on the command line to copy a directory, and translate that into what programming using the Net::SFTP module is required.

    meh.
Re: how copy dir in NET::SFTP
by Argel (Prior) on Jul 11, 2006 at 17:36 UTC
    From the little exposure I have had to the Net:: protocols they seem to try to provide a low-level interface that implements the protocol, to be used as building blocks for people to actually write user friendly (hopefully) clients and servers in. Sometimes some more convenient subroutines are also thrown in. Which pretty much covers Net::SFTP. The real power of it is the low-level calls, not the simpler extras.

    I think we have a tendancy to take for granted even the most basic of conveniences in these types of clients. For example, does the File Transfer Protocol (FTP) have an mput and mget designed in or is it actually something the client and server software implement? I know which way I would bet....

    Anyway, as others have mentioned, you will either need to create the local directory yourself and then build a list of files to get one at a time or take a look at jdtoronto's suggestion of using Net::SFTP::Recursive.

    If you have the time to learn and experiment I'd suggest trying to do it yourself -- you will come to a much better understanding of how SFTP works and (generalizing a bit) how other client/server based protocols actually work.