connection to samba server

David M. Wilson at
Mon Dec 15 04:25:29 CET 2003

"Przemo Drochomirecki" <pedrosch at> wrote...

> does anyone knows how to connect to samba server (from windows)

Hello there.

Your question isn't particularly clear, however I can assume you mean
something more like "can anyone help me establish a connection to a
Samba server from Python under Windows?"

In which case, the clearest solution might be to use a suitable
Windows API call to map the remote Samba computer's share to a local
drive letter, then just access the remote Samba files via that drive
letter, eg.:

    def map_drive(local, remote, username = None, password = None):
        return win32wnet.WNetAddConnection2(
            local, remote, None,
            username, password,

    def unmap_drive(...):

    map_drive("Z:", r"\\mum\my_share")
    # <use os.listdir to determine contents of Z:, and process>

Alternatively if your share does not require authentication (ie. you
are pre-authenticated to the Samba server, or it has guest shares),
you may directly use UNC pathnames to access the share, eg.:

    # will throw 'invalid argument' if you are not authenticated.
    # etc.

Alternatively, you could prepend the UNC path to each file you wish to
access, although this may be considerably slower:

    to_process = [ 'input1.txt', 'input2.txt', 'job.ctl' ]
    unc_path = r'\\mum\my_share'

    for filename in to_process:
        pathname = os.path.join(unc_path, filename)
        processee = open(pathname)


Hope that helps. To the other respondees, answering in the unhelpful
manner that you did makes you no more than trolls. Has it ever crossed
your mind that in some parts of the world, the education necessary to
communicate in the accepted pythonic anal way, might not be readily

You may argue that it is better to teach someone how to ask a question
correctly, but I would rather see it as being a poor example of your

It is quite possible (gathering from the way he posted) that this
poster has never before talked on a Python user list. How do you think
he feels about his first experience with fellow Python programmers,
good or bad?

Nothing agitates me more on the Internet than people wasting each
other's time in this manner. True, the poster wasn't particularly
clear, but do you have a right to demand he posts in clear well
defined English?

The Internet is a global medium, and despite popular assumption,
English is not an Internet standard. I have as much right to post in
native Belfast slang as you have to post in well written English.
Please learn to be accepting of one another, it is so much more
helpful than to try to correct something that shouldn't be corrected.
The original poster was well meaning, was your reply?

If you didn't understand the question then don't reply. Others may
well do, and the poster will quickly work out whether or not he is
being clear by the number of replies he receives.

By doing the usual "person isn't being clear, lets make an example of
him" dance, you wasted not only your own time, but his, everyone who
reads your pointless thread, and some megabytes of Internet bandwidth
to boot.



More information about the Python-list mailing list