Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I have been a grateful member of this site for several years. I love this site and refer everyone to it!..."

Geography

Where in the world do Tek-Tips members come from?

SFTP error on call to open /dev/urandom

ajdavis (Programmer)
24 Mar 08 12:02
I'm changing a script from using FTP to SFTP.  I have this code:

CODE

    print "Trying to connect to $host.\n";

    if ( $sftp = Net::SFTP->new( "$host" ) )
    {
        print "Connected to $host.\n";
        $connected = "true";
    }
    else
    {
        $rc = 1;
        push @ERRORS, "Can't connect to $host: $!\n";
    }
    
and I get the following error.

Quote:

Trying to connect to host_name. (output from my code)
Couldn't open /dev/urandom at /usr/local/lib/perl5/site_perl/5.8.8/Crypt/DH.pm line 96.
The code in DH.pm is:

CODE

sub _makerandom {
    my $size = shift;

    my $bytes = int($size / 8) + ($size % 8 ? 1 : 0);

    my $rand;
    if (-e "/dev/urandom") {
        my $fh;
        open($fh, '/dev/urandom')
            or die "Couldn't open /dev/urandom";

        my $got = sysread $fh, $rand, $bytes;
        die "Didn't read all bytes from urandom" unless $got == $bytes;
        close $fh;
    } else {
        for (1..$bytes) {
            $rand .= chr(int(rand(256)));
        }
    }

    my $bits = unpack("b*", $rand);
    die unless length($bits) >= $size;

    Math::BigInt->new('0b' . substr($bits, 0, $size));
}
but as you can see, the code was able to see the existence of /dev/urandom before trying to open it.  
Here are the permissions for /dev/urandom

Quote:

=> ls -l /dev/urandom
crw-r--r--   1 root     system       40,  1 May 21 2007  /dev/urandom
So I'm not sure why it can't read from it.  I've been looking on-line and haven't found anything that would help.  Any suggestions as to how to fix this or get around it?   

Thanks in advance.
Josh

ajdavis (Programmer)
28 Mar 08 11:56
I decided to go the Net::SFTP::Foreign route but I'm getting a different error with it on the ->put() call.  I'll search the posts for this error and repost if I can't find anything.

CODE

#!/usr/bin/perl -X

use Net::SFTP::Foreign;

my $host = "";
my $username = "";
my $password = "";
my $directory = "";
$Net::SFTP::Foreign::debug = 1;

my $sftp = Net::SFTP::Foreign->new( "$username\@$host", password => $password );
$sftp->setcwd( "$directory" );
$sftp->put( "test_file.txt" => "test_file.txt" );

if ( $sftp->error )
{
    print "Put error: " . $sftp->error . "\n";
    print "Put status: " . $sftp->status . "\n";
}

Quote:

=> perl test2.pl
# queueing msg len: 5, code:1, id:3 ... [1]
# waiting for message... [1]
# got it!, len:5, code:2, id:3, status: -
# queueing msg len: 15, code:16, id:0 ... [1]
# waiting for message... [1]
# got it!, len:63, code:104, id:0, status: -
# queueing msg len: 42, code:3, id:1 ... [1]
# waiting for message... [1]
# got it!, len:10, code:102, id:1, status: -
# queueing msg len: 18, code:10, id:2 ... [1]
# waiting for message... [1]
# got it!, len:106, code:101, id:2, status: 3
# queueing msg len: 10, code:4, id:3 ... [1]
# waiting for message... [1]
# got it!, len:40, code:101, id:3, status: 0
Put error: Couldn't setstat remote file (fsetstat): The requested operation cannot be performed because there is a file transfer in progress.
Put status: The requested operation cannot be performed because there is a file transfer in progress.
stevexff (Programmer)
28 Mar 08 12:43
In the OP you don't say why /dev/urandom can't be opened. Try changing the line in DH.pm to

CODE

die "Couldn't open /dev/urandom: $!";
to see if it gives you any more info.

Steve

"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::PerlDesignPatterns)

ajdavis (Programmer)
28 Mar 08 14:28
DH.pm is part of the default installation and I only have read permission to that file.  I'm not an admin on this box so I can't change it.  Sorry.  

Thanks for looking at this though.  I do appreciate it.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close