Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8849879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:46:06+00:00 2026-06-14T12:46:06+00:00

I’m working on a perl script using net::ssh2 to make a SSH connection to

  • 0

I’m working on a perl script using net::ssh2 to make a SSH connection to a remote server.
(I’m working on windows)

I chose Net::SSH2 because i had to make some SFTP connections in the same script.

For now, my sftp connections work perfectly. The problem is when i try to execute a “long-duration” command. I mean a command which execution can take more than 30sec.

    $ssh2 = Net::SSH2->new();
    $ssh2->connect('HOST') or die;
    if($ssh2->auth(username=>'USER', password=>'PSWD'))
    {
        $sftp = Net::SFTP::Foreign->new(ssh2=>$ssh2, backend=>'Net_SSH2');
        $sftp->put('local_path', 'remote_path');
        $channel=$ssh2->channel();
    ##
        $channel->shell('BCP_COMMAND_OR_OTHER_PERL_SCRIPT');
    # OR (I tried both, both failed :( )
        $channel->exec('BCP_COMMAND_OR_OTHER_PERL_SCRIPT');
    ##
        $channel->wait_closed();
        $channel->close();
        print "End of command";
        $sftp_disconnect();
    }
    $ssh2->disconnect();

When i execute this script, the connection is successfull, the file is correctly sent but the execution is not (completely) performed. I mean, I think the command is sent for execution but terminated immediatly or not sent at all, i’m not sure.

What i want is the script waits until the command is completly finished before disconnect everything (just because sometimes, i need to get the result of the command execution)

Does anyone know how to solve this? 🙁 The cpan documentation is not very explicit for this

Thanks!

PS: I’m open to any remarks or suggestion 🙂

Edit: After some test, i can say that the command is sent but is interrupted. My test was to start another perl script on the remote server. This script writes in a flat file. In this test, the script is started, the file is half-filled. I mean, the file is brutaly stopped in the middle.

In the other hand, when i performed a “sleep(10)” just after the “$channel->exec()”, the script goes to the end successfully.
Problem is, that I can’t write a “sleep(10)” (i don’t know if it will take 9 or 11 seconds (or more, you see my point)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T12:46:08+00:00Added an answer on June 14, 2026 at 12:46 pm

    You can try using Net::SSH::Any instead.

    It provides a higher level and easier to use API and can use Net::SSH2 or Net::OpenSSH to handle the SSH connection.

    For instance:

    use Net::SSH::Any;
    
    my $ssh = Net::SSH::Any->new($host, user => $user, password => $password);
    $ssh->error and die $ssh->error;
    
    my $sftp = $ssh->sftp;
    $sftp->put('local_path', 'remote_path');
    
    my $output = $ssh->capture($cmd);
    print "command $cmd output:\n$output\n\n";
    
    $sftp->put('local_path1', 'remote_path1');
    
    # no need to explicitly disconnect, connections will be closed when
    # both $sftp and $ssh go out of scope.
    

    Note that SFTP support (via Net::SFTP::Foreign) has been added on version 0.03 that I have just uploaded to CPAN.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a small JavaScript validation script that validates inputs based on Regex. I
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have an autohotkey script which looks up a word in a bilingual dictionary
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.