RE: How to get a network resource on a windows server

2005-12-01 Thread Tim Golden
[Frank.Lin]

 I am working in windows environment and I 
 want copy some files from a remote share folder.

 Now I want to let my script establish a 
 connection between NULL device name and a 
 shared resource then return a list of files 
 matching the given pattern and copy them
 to local host

It's not entirely clear exactly what you're trying
to do. I'll present some (hopefully) useful tips
based on a bit of guesswork. I'm assuming you're
familiar with the various ways of copying things
around (copy, xcopy, robocopy, Python's shutil
module) but feel free to come back and ask if
that's where the stumbling block is.

WARNING: Code snippets are untested.


Guess 1) 
You're trying to copy, eg, \\server\share\*.txt 
to somewhere local, eg c:\temp.

You could simply let the OS do the work for you:

code
import os

os.system (rcopy \\server\share\*.txt c:\temp)
/code



Guess 2)
You're trying to do something a bit more fancy
which requires you to make a local connection
to the remote share. NB You *don't* need to do
this just to copy files, but let's imagine you
have some other purpose in mind.

You can use the win32wnet module from the pywin32
extensions to map the drive, and then use the
os or any other technique to copy the files.

code
import win32wnet
import win32netcon

win32wnet.WNetAddConnection2 (
  win32netcon.RESOURCETYPE_DISK,
  Z:,
  r\\server\share,
  None,
  None,
  None,
  0
)

# then os.system (rcopy z:\*.txt c:\temp) or whatever
/code


Guess 3)
You need to create an authenticated connection
using the NULL device. (Re-reading, this is
the most likely interpretation of your question).

Use the win32wnet module again, this time passing
in no device, but adding a username/password

code
import win32wnet
import win32netcon

win32wnet.WNetAddConnection2 (
  win32netcon.RESOURCETYPE_DISK,
  None,
  r\\server\share,
  None,
  username,
  password,
  0
)

# then os.system (rcopy \\server\share\*.txt c:\temp) or whatever
/code



This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get a network resource on a windows server

2005-12-01 Thread Frank.Lin
Hi TIm :
The 3rd case fit me and all tips are useful   ^_^
Thanks for you help!
--
On Thu, 1 Dec 2005 08:49:42 -, Tim Golden wrote:

It's not entirely clear exactly what you're trying
to do. I'll present some (hopefully) useful tips
based on a bit of guesswork. I'm assuming you're
familiar with the various ways of copying things
around (copy, xcopy, robocopy, Python's shutil
module) but feel free to come back and ask if
that's where the stumbling block is.

-- 
http://mail.python.org/mailman/listinfo/python-list


How to get a network resource on a windows server

2005-11-30 Thread Frank.Lin
I am new to learn program. please do me a favor. 

I am working in windows environment and I want copy some files from a
remote share folder.

I formerly mapped these share folers to a local device, then run my
python script to copy files matching the given pattern to destination
folder and deal with them

Now I want to let my script establish a connection between NULL device
name and a shared resource
then return a list of files matching the given pattern and copy them
to local host

I have installed Window Extensions but I do not know how to operate
this romote resource. 

who can give some instruction or a sample about it.  thanks!


best  reagards
Frank Lin
-- 
http://mail.python.org/mailman/listinfo/python-list