How to open a remote file using python.

V

venutaurus539

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
 
C

Chris Rebert

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
 
M

MRAB

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().)
 
V

venutaurus539

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

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.
 
O

odeits

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


        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)
 
C

Chris Rebert

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


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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top