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.


In reply to SCP session by TechFly

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.