TechFly has asked for the wisdom of the Perl Monks concerning the following question:
Hi all;
I have an issue. I am trying to rewrite a bunch of scripts to move files around between web servers, and stage servers. The issue I have is this: there are some network issues. I cannot fix them. They are being worked on by someone else, but it is creating a lot of work for me. I don't like a lot of work, so I am doing this.
The old scripts are written in bash, and when they move files, they connect to the remote server, copy one file, and then disconnect. They do this several hundred times. I figure I can do this better in perl, so I started out with this:
#!/usr/bin/perl use warnings; use strict; use Net::SCP qw(scp); my $scp = Net::SCP->new( "servername", "username" ) or die "Cannot con +nect: "; $scp->cwd("/tmp/test"); $scp->get("gettest"); while (</tmp/test/*>) { #print $_ . "\n"; $scp->put($_) or die "Could not place file: " . $scp->{errstr}; }
There is a problem though. It does the same thing. I need to connect and stay connected while I transfer files. I found the cpan info on Net::SCP, and it seems to have a batch mode, and it creates a *reader, and a *writer. I don't know how to use these, and have been unsuccessful in getting further information. Can someone point me in the right direction? What exactly is the *reader, and *writer? What is the proper name for the method being used? They are found in this snippet from the cpan site:
use Net::SSH qw(sshopen2); use strict; my $user = "username"; my $host = "hostname"; my $cmd = "command"; sshopen2("$user\@$host", *READER, *WRITER, "$cmd") || die "ssh: $!"; while (<READER>) { chomp(); print "$_\n"; } close(READER); close(WRITER);
My humble thanks to you all.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: SCP session
by salva (Canon) on Nov 10, 2011 at 20:19 UTC | |
by TechFly (Scribe) on Nov 10, 2011 at 20:23 UTC | |
by bart (Canon) on Nov 10, 2011 at 20:43 UTC | |
|
Re: SCP session
by choroba (Cardinal) on Nov 10, 2011 at 22:42 UTC | |
by Anonymous Monk on Nov 11, 2011 at 14:28 UTC | |
|
Re: SCP session
by hbm (Hermit) on Nov 10, 2011 at 20:42 UTC | |
by TechFly (Scribe) on Nov 10, 2011 at 20:52 UTC | |
by Eliya (Vicar) on Nov 10, 2011 at 20:59 UTC |