Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Connecting to network shared drive

by murtu_4u (Initiate)
on May 27, 2008 at 16:33 UTC ( [id://688686]=perlquestion: print w/replies, xml ) Need Help??

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

Hi. I need to connect to a network shared drive and poll a directory for incoming files. I have the path of the drive as we would use it in IE \\machinename\abc\pqr\ I think i would need the absolute path on that machine right? How do i get that? Once i get that how do i connect and do this?

Replies are listed 'Best First'.
Re: Connecting to network shared drive
by psini (Deacon) on May 27, 2008 at 16:55 UTC

    Which is the protocol you use to share the drive? SMB? And which is the OS on the machine that needs connecting? Who is the owner of the share? The user that should run the connecting script has access to the share?

    Too many question, too little information...

    Rule One: Do not act incautiously when confronting a little bald wrinkly smiling man.

Re: Connecting to network shared drive
by NetWallah (Canon) on May 27, 2008 at 17:10 UTC
    From your description of the path/drive, it appears that you are accessing the path from some version of Windows.

    You do NOT need the absolute path.

    The simplest way to read the directory is to use the perl opendir, readdir,closedir functions.

    (Of course you need to ensure that you have the appropriate privileges to access the remote directory.

    There are modules in CPAN (like File::Set) that will assist polling the directory, and notifying you of changes.

         "A fanatic is one who redoubles his effort when he has forgotten his aim."—George Santayana

Re: Connecting to network shared drive
by ikegami (Patriarch) on May 28, 2008 at 00:14 UTC

    Windows has invisible shares called C$, D$, etc representing C:, D:, etc.

    If the machine you wish to poll has file sharing enabled,
    if the machine on which the program runs is a Win32 machine with "Client for Microsoft Networks" enabled, and
    if your login and password is the same for that machine as it is for the current machine,
    then you can just open \\machine\c$\some\dir (or //machine/c$/some/dir if it's easier) using opendir. Win32::ChangeNotify will also accepts such a path.

    use strict; use warnings; my $path = '\\\\godzilla\\c$\\temp'; for (;;) { my $count = () = do { opendir my $dh, $path or die; readdir($dh) }; print("$count\n"); sleep(2); }
    2 2 2 2 3 3 3 4 Terminating on signal SIGINT(2)
    use strict; use warnings; use Win32::ChangeNotify qw( FILE_NOTIFY_CHANGE_DIR_NAME FILE_NOTIFY_CHANGE_FILE_NAME ); my $path = '\\\\godzilla\\c$\\temp'; for (;;) { my $count = () = do { opendir my $dh, $path or die; readdir($dh) }; print("$count\n"); my $notify = Win32::ChangeNotify->new($path, 0, FILE_NOTIFY_CHANGE_ +DIR_NAME|FILE_NOTIFY_CHANGE_FILE_NAME); $notify->wait or die; }
    2 3 4 Terminating on signal SIGINT(2)

    Update: Added code.

Re: Connecting to network shared drive
by mhearse (Chaplain) on May 27, 2008 at 23:57 UTC
    Assuming you are working on *nix, you could use smbclient. There is also a perl api, with many examples.
Re: Connecting to network shared drive
by leocharre (Priest) on May 27, 2008 at 17:10 UTC
    I second that motion- We do this at work here with samba (smb). It lets people use their windz machines too, we then use linux boxes to sort out the stuff.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://688686]
Approved by moritz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-03-28 20:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found