title: how to upload files on a windows sharing network using python
body: <p>I am using a mac machine. I have access to a windows share network. I am able to connect to it from my mac using 'smb://location'.</p>
  
  <p>Using python, I want to be able to download/upload files on the windows share network using my access credentials. How can I do it.</p>
  
  <p>The shared location looks like <code>smb://v1/abc</code>. I am able to connect to this. Now I want to create a file in a folder within this connection.</p>
  
  <p>I want to create a file inside the folder <code>d2</code>. I tried using <a href="http://pythonhosted.org/pysmb/api/smb_SMBConnection.html" rel="nofollow"><code>pysmb</code></a> module. I tried the following:</p>
  
  <pre><code>&gt;&gt;&gt; fp = open('local_file.txt', 'w')
  &gt;&gt;&gt; conn = SMBConnection('user', 'password', 'test_v1','v1', use_ntlm_v2 = True)
  &gt;&gt;&gt; conn.retrieveFile('share', 'abc/d2/check.csv', fp)
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "/Users/8417/repos/workspace/venv/lib/python2.7/site-packages/smb/SMBConnection.py", line 267, in retrieveFile
      return self.retrieveFileFromOffset(service_name, path, file_obj, 0L, -1L, timeout)
    File "/Users/8417/repos/workspace/venv/lib/python2.7/site-packages/smb/SMBConnection.py", line 283, in retrieveFileFromOffset
      raise NotConnectedError('Not connected to server')
  smb.base.NotConnectedError: Not connected to server
  </code></pre>
  
  <p>Also tried:</p>
  
  <pre><code>&gt;&gt;&gt; conn = SMBConnection('user', 'password', 'test_v1','v1/abc', use_ntlm_v2 = True)
  &gt;&gt;&gt; conn.retrieveFile('share', 'd2/check.csv', fp)
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "/Users/8417/repos/workspace/venv/lib/python2.7/site-packages/smb/SMBConnection.py", line 267, in retrieveFile
      return self.retrieveFileFromOffset(service_name, path, file_obj, 0L, -1L, timeout)
    File "/Users/8417/repos/workspace/venv/lib/python2.7/site-packages/smb/SMBConnection.py", line 283, in retrieveFileFromOffset
      raise NotConnectedError('Not connected to server')
  smb.base.NotConnectedError: Not connected to server
  </code></pre>