Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-25 15:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found