|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Newbie help with mapping drives and stuff
Hi
I am just starting to learn python and thought I would start with a little job I need doing, I need to grab a file from another machine and copy it to my own. (both Windows machines). I would though need to authenticate on the other box though. Would it be best to map a drive from Python, or is there better ways?? Has anybody got any ideas where I start with this, I would just like a little start so I can then start building onto the program. (and hopfully learn more (I have the "Learning Python" book, so I have some hope)). Thanks for looking and any ideas would be fantastic. |
|
#2
|
|||
|
|||
|
People often seem to ask for Windows-specific tasks which can be done in Python, but not particularly elegantly.
There is a brilliant module for running commands on Linux called "commands", but it doesn't work on Windows. ![]() The full command you want is something like: Code:
c:\windows\system32\net.exe use G: \\computer\share /USER:computername\username password And the module you need is os, with the spawnv function. Which is ugly and *extremely* fussy. Try something like: Code:
import os
result = os.spawnv(os.P_WAIT, "c:/windows/system32/net.exe", ("net.exe", "use", "G:",
"\\\\computer\\share", "/USER:computer\\username", "password"))
if result == 0:
print "Share mapped correctly"
else:
print "Share mapping failed"
![]() [/code] This will wait until the command returns, so you wont be able to run it, try to copy a file, and then find it hasn't finished mapping the drive yet. Regarding a better way: I would probably try setting up a user account on the remote computer with the same username and password that you use on the local computer, and copying the file straight with a "\\computer\share\file.name" path. (remember, you need to double the backslashes in Python, or use \\\\computer/share/file.name). |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Newbie help with mapping drives and stuff |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|