ibanix has asked for the wisdom of the Perl Monks concerning the following question:

Greetings again,

I've got some code that copies files from one Windows network share to another, ie from \\server1\share to \\server2\share. Before I do the copying, however, I want to verify that the server running the script can connect to this share; ie that it exists and I can read from it.

Here's what I've been using:
my $connect_shr = 'net use \\\\'.$server.'\\'.$share; my $result_shr = `$connect_shr`;
And then I can process $result_shr. The problem here is that if the script can't connect to the server\share pair, the net use command blocks until an error code is returned. This takes anywhere from seconds to minutes on my systems.

Is there a better way to do this?

Cheers,
ibanix

$ echo '$0 & $0 &' > foo; chmod a+x foo; foo;

Replies are listed 'Best First'.
Re: [Win32] Verifying network connection
by BrowserUk (Patriarch) on Dec 09, 2002 at 22:06 UTC

    Take a look at Win32::NetResource::AddConnection(). I believe this came as a part of the AS distribution.

    I haven't tried this across a network, but it seems to timeout more quickly than the net command locally.


    Okay you lot, get your wings on the left, halos on the right. It's one size fits all, and "No!", you can't have a different color.
    Pick up your cloud down the end and "Yes" if you get allocated a grey one they are a bit damp under foot, but someone has to get them.
    Get used to the wings fast cos its an 8 hour day...unless the Govenor calls for a cyclone or hurricane, in which case 16 hour shifts are mandatory.
    Just be grateful that you arrived just as the tornado season finished. Them buggers are real work.

Re: [Win32] Verifying network connection
by particle (Vicar) on Dec 09, 2002 at 23:11 UTC