Python copy files from Linux to WIndows
<p>I'm building a website which has a form which captures user data and runs some cgi on the user data.  One of the first steps of the cgi is that it needs to copy files from the linux webserver to windows machines.  The server would be using an active directory role acount for the copy credential.  I had hoped to simply use something like this:</p>

<p><pre><code></p>

<pre><code>mount -t cifs -o username=someUsername,password=somePasword //someMachine/someShare /someMountPoint
</code></pre>

<p></pre></code></p>

<p>Unfortunately I get errors about the password attributed being invalid when I run that command in bash.  Ideally I would use this method to mount the remote windows c$ share and then copy the files but I'm willing to try other modules if they make more sense.</p>

<p>I had something like this but it doesn't work, creates the necessary temporary directories but never mounts anything.  I'm happy to try using something else but would love to know what's wrong here.
<pre><code></p>

<pre><code>import subprocess
import random


def makeDir():
    tempDir = random.randrange(111111,999999)
    subprocess.Popen(["mkdir","/mntDir/"+str(tempDir)])
    return tempDir

def mountShare(hostname, username, password):
    mountDir = makeDir()
    try:
        subprocess.Popen(["mount","-t","cifs", "-o",
                      "username="+username+",password="+password,
                      "//"+hostname+"/c$",
                      "/mntDir/"+mountDir])
    except:
        print("Mounting failed")
</code></pre>

<p></pre></code></p>

<p>This approach has two drawbacks: the first one is that you mount windows share from your webserver. You don;t need to mount it dynamically and in no account you should not mount it for every request. Separate your implementation and infrastructure. Mount required directory in /etc/fstab and let your webserver to rely on existence of the directory.</p>

<p>But then there is another problem: what for you are copying the files to another machine? Do you want to process them there? How you want to notify windows machine that it needs to process data? Why not to run another web server on it and send it requests when you need to process something. And at this point you can drop all that network file systems and send the files within the requests. So you will have linux based frontend server which performs some actions by sending HTTP requests to windows backend server. This will also allow you to notify frontend when the processing is ready.</p>

python linux windows cifs