How to open a remote file using python.

Discussion in 'Python' started by venutaurus539@gmail.com, Feb 23, 2009.

  1. Guest

    Hello all,
    I am writing an application where I need to open a shared
    file on a remote machine using python script. I tried using the
    following function:

    f = urllib.open("\\remote_machine\\folder1\\file1.doc")

    I also tried using

    class urllib.FancyURLopener(...)

    but didn't work. Can some one help me in this regard.

    Thank you in advance,
    Venu
     
    , Feb 23, 2009
    #1
    1. Advertising

  2. Chris Rebert Guest

    On Sun, Feb 22, 2009 at 8:13 PM,
    <> wrote:
    > Hello all,
    > I am writing an application where I need to open a shared
    > file on a remote machine using python script. I tried using the
    > following function:
    >
    > f = urllib.open("\\remote_machine\\folder1\\file1.doc")
    >
    > I also tried using
    >
    > class urllib.FancyURLopener(...)
    >
    > but didn't work. Can some one help me in this regard.


    That function and class are be for retrieving materials over the web
    (typically HTTP/FTP); however, your path suggests you're trying to
    access a file over a local Windows network, so those aren't
    appropriate. The regular open() function would have a better chance of
    working for this. Have you tried it?

    Cheers,
    Chris

    --
    Follow the path of the Iguana...
    http://rebertia.com
     
    Chris Rebert, Feb 23, 2009
    #2
    1. Advertising

  3. MRAB Guest

    wrote:
    > Hello all,
    > I am writing an application where I need to open a shared
    > file on a remote machine using python script. I tried using the
    > following function:
    >
    > f = urllib.open("\\remote_machine\\folder1\\file1.doc")
    >
    > I also tried using
    >
    > class urllib.FancyURLopener(...)
    >
    > but didn't work. Can some one help me in this regard.
    >

    What do you mean by "remote machine"? Do you mean you want to open a
    file that's in a shared folder on a machine that's on the same local
    network?

    If it's meant to be a Windows filepath then it should be:

    f = open(r"\\remote_machine\folder1\file1.doc")

    (If the file is a Microsoft Word document file, then you won't probably
    be able to make much sense of its contents using open().)
     
    MRAB, Feb 23, 2009
    #3
  4. Guest

    On Feb 23, 9:25 am, MRAB <> wrote:
    > wrote:
    > > Hello all,
    > >            I am writing an application where I need to open a shared
    > > file on a remote machine using python script. I tried using the
    > > following function:

    >
    > > f = urllib.open("\\remote_machine\\folder1\\file1.doc")

    >
    > >          I also tried using

    >
    > > class urllib.FancyURLopener(...)

    >
    > >          but didn't work. Can some one help me in this regard..

    >
    > What do you mean by "remote machine"? Do you mean you want to open a
    > file that's in a shared folder on a machine that's on the same local
    > network?
    >
    > If it's meant to be a Windows filepath then it should be:
    >
    >      f = open(r"\\remote_machine\folder1\file1.doc")
    >
    > (If the file is a Microsoft Word document file, then you won't probably
    > be able to make much sense of its contents using open().)


    Thanks to all for your brisk replies:

    Yes, my aim is to open a file from another machine in the same
    LAN. It also worked using

    >>f = urllib.urlopen("\\\remote_machine\\folder\\file.doc")


    But now I also have to copy the same file to the local machine
    in Python. Do I need to follow any protocols for this?

    Thank you,
    Venu.
     
    , Feb 23, 2009
    #4
  5. odeits Guest

    On Feb 22, 9:02 pm, ""
    <> wrote:
    > On Feb 23, 9:25 am, MRAB <> wrote:
    >
    >
    >
    > > wrote:
    > > > Hello all,
    > > >            I am writing an application where I need to open a shared
    > > > file on a remote machine using python script. I tried using the
    > > > following function:

    >
    > > > f = urllib.open("\\remote_machine\\folder1\\file1.doc")

    >
    > > >          I also tried using

    >
    > > > class urllib.FancyURLopener(...)

    >
    > > >          but didn't work. Can some one help me in this regard.

    >
    > > What do you mean by "remote machine"? Do you mean you want to open a
    > > file that's in a shared folder on a machine that's on the same local
    > > network?

    >
    > > If it's meant to be a Windows filepath then it should be:

    >
    > >      f = open(r"\\remote_machine\folder1\file1.doc")

    >
    > > (If the file is a Microsoft Word document file, then you won't probably
    > > be able to make much sense of its contents using open().)

    >
    > Thanks to all for your brisk replies:
    >
    >         Yes, my aim is to open a file from another machine in the same
    > LAN. It also worked using
    >
    > >>f = urllib.urlopen("\\\remote_machine\\folder\\file.doc")

    >
    >         But now I also have to copy the same file to the local machine
    > in Python. Do I need to follow any protocols for this?
    >
    > Thank you,
    > Venu.


    the copy in shutil will work just fine.
    import shutil
    shutil.copy(remotepath,localpath)
     
    odeits, Feb 23, 2009
    #5
  6. Chris Rebert Guest

    On Sun, Feb 22, 2009 at 9:02 PM,
    <> wrote:
    > On Feb 23, 9:25 am, MRAB <> wrote:
    >> wrote:
    >> > Hello all,
    >> > I am writing an application where I need to open a shared
    >> > file on a remote machine using python script. I tried using the
    >> > following function:

    >>
    >> > f = urllib.open("\\remote_machine\\folder1\\file1.doc")

    >>
    >> > I also tried using

    >>
    >> > class urllib.FancyURLopener(...)

    >>
    >> > but didn't work. Can some one help me in this regard.

    >>
    >> What do you mean by "remote machine"? Do you mean you want to open a
    >> file that's in a shared folder on a machine that's on the same local
    >> network?
    >>
    >> If it's meant to be a Windows filepath then it should be:
    >>
    >> f = open(r"\\remote_machine\folder1\file1.doc")
    >>
    >> (If the file is a Microsoft Word document file, then you won't probably
    >> be able to make much sense of its contents using open().)

    >
    > Thanks to all for your brisk replies:
    >
    > Yes, my aim is to open a file from another machine in the same
    > LAN. It also worked using
    >
    >>>f = urllib.urlopen("\\\remote_machine\\folder\\file.doc")

    >
    > But now I also have to copy the same file to the local machine
    > in Python. Do I need to follow any protocols for this?


    You may find urllib.urlretrieve() useful for accomplishing that.

    Cheers,
    Chris

    --
    Follow the path of the Iguana...
    http://rebertia.com
     
    Chris Rebert, Feb 23, 2009
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Holmes

    Problem using Remote Site to open website

    John Holmes, Jan 31, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    419
    John Holmes
    Jan 31, 2006
  2. ml
    Replies:
    0
    Views:
    1,475
  3. ml
    Replies:
    2
    Views:
    4,887
    John C. Bollinger
    Nov 30, 2004
  4. davidj411
    Replies:
    7
    Views:
    3,347
    Tim Golden
    Oct 8, 2009
  5. Dayton Jones

    Remote.pm (File::Remote) problem

    Dayton Jones, Mar 1, 2006, in forum: Perl Misc
    Replies:
    9
    Views:
    213
    Dayton Jones
    Mar 3, 2006
Loading...

Share This Page