Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 27th, 2004, 11:08 AM
LedZep LedZep is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 1 LedZep User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old September 30th, 2004, 04:25 PM
sfb sfb is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 447 sfb User rank is Corporal (100 - 500 Reputation Level)sfb User rank is Corporal (100 - 500 Reputation Level)sfb User rank is Corporal (100 - 500 Reputation Level)sfb User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 1 h 43 m 45 sec
Reputation Power: 10
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).

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Newbie help with mapping drives and stuff


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT