Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Perl and SSH and ftp/scp

by hakkr (Chaplain)
on Jun 26, 2002 at 09:36 UTC ( #177342=perlquestion: print w/replies, xml ) Need Help??
hakkr has asked for the wisdom of the Perl Monks concerning the following question:

I have found the Net::SSH module. How do I use it to secure copy files from from my server. Is it just a matter of logging in and issuing some remote cp command. If this is not possible can I use this module with Net::Ftp to achieve secure ftp tunneling. Is there maybe a Net::SFTP ? thanks

Replies are listed 'Best First'.
Re: Perl and SSH and ftp/scp
by Kanji (Parson) on Jun 26, 2002 at 09:43 UTC
Re: Perl and SSH and ftp/scp
by ariels (Curate) on Jun 26, 2002 at 09:40 UTC
    CPAN also has a module Net::SFTP, which might be more suited to your needs. (I've not used it, so I cannot comment further.)
Re: Perl and SSH and ftp/scp
by grantm (Parson) on Jun 26, 2002 at 11:20 UTC

    I haven't had much luck with the SSH modules on platforms other than Linux, but this sort of thing is fairly portable:

        system("scp file host:file")

    (I use pscp from the putty package on Windows).

Re: Perl and SSH and ftp/scp
by Aristotle (Chancellor) on Jun 26, 2002 at 17:13 UTC

    Untested dirty hack ahead.

    use warnings; use strict; use Net::SSH qw(sshopen2); my $user = "username"; my $host = "hostname"; my $localfile = "~/example.local"; my $remotefile = "~/example.remote"; sshopen2("$user\@$host", *READER, *WRITER, "cat > $remotefile") || die + "ssh: $!"; open INFILE, "<", $localfile; print WRITER $_ while sysread INFILE, $_, 8192; close(INFILE); close(READER); close(WRITER);
    Use scp or Net::SFTP instead.

    Makeshifts last the longest.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://177342]
Approved by rob_au
[ovedpo15]: can't I use just use lib $FindBin::Bin/../ bin" asuming that p2 is in ./bin and p1 is in /config? it says "cant find" altought p2 is
[moritz]: ovedpo15 "use lib" is only for .pm files
[moritz]: if you don't have .pm file, you might to use "require" or "do" with an absolute path
[ovedpo15]: I need to use FindBin thought. does FindBin finds only modules? or it can find perl script also?
[moritz]: maybe you should start looking at the documentation of FindBin?

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2018-03-17 20:47 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (226 votes). Check out past polls.