Well, the solution seems to be something like (windows only)
import os
import os.path
import shutil
import sys
import win32wnet
def wnet_connect(host, username, password):
unc = ''.join(['\\\\', host])
try:
win32wnet.WNetAddConnection2(0, None, unc, None, username, password)
except Exception, err:
if isinstance(err, win32wnet.error):
# Disconnect previous connections if detected, and reconnect.
if err[0] == 1219:
win32wnet.WNetCancelConnection2(unc, 0, 0)
return wnet_connect(host, username, password)
raise err
if __name__ == '__main__':
node = hostname
dst = r'C:\temp\destination__'
dst += node + r'.txt'
wnet_connect(node,username,password)
shutil.copyfile(r'\\' + node + r'\c$\temp\\al_lsf_log',dst)
Gabriel Genellina wrote:
En Thu, 27 Mar 2008 00:34:20 -0300, Astan Chee <[EMAIL PROTECTED]> escribió:
I have a file on another machine on the local network (my machine and
local machines are on windows) and I want to copy it locally. Now the
machine requires authentication and when I try to do a
import shutil
shutil.copy(r'\\remotemachine\c$\temp\filename',r'C:\folder\test.txt')
and it gives me a IOError: [Errno 13] Permission denied: error, which I
expect. How do I provide authentication to copy this file?
Probably there are other ways, but the "net use" command looks easy
enough. Execute "net help use | more" in a console to see the right syntax.
Use the subprocess module to run the command from inside Python.
--
"Formulations of number theory: Complete, Consistent, Non-trivial. Choose two."
Animal Logic
http://www.animallogic.com
Please think of the environment before printing this email.
This email and any attachments may be confidential and/or privileged. If you
are not the intended recipient of this email, you must not disclose or use the
information contained in it. Please notify the sender immediately and delete
this document if you have received it in error. We do not guarantee this email
is error or virus free.
--
http://mail.python.org/mailman/listinfo/python-list