Copying files from SMB server to local drive(Linux/Windows) in python

python

Solution

According to some documentation, `SMBConnection.retrieveFile()` is the function you are searching for.

Example:

# UNTESTED
conn = SMBConnection('salead',
                     'repo@2k12',
                     '192.168.14.1',
                     'SERVER',
                     use_ntlm_v2 = True)
assert conn.connect('192.168.1.41', 139)
with open('local_file', 'wb') as fp:
    conn.retrieveFile('share', '/path/to/remote_file', fp)

Documentation: http://pysmb.readthedocs.io/en/latest/api/smb_SMBConnection.html

Example (in Japanese): http://symfoware.blog68.fc2.com/blog-entry-999.html

Problem

I am using smb module to connect to smb server. I am unable to figure out what exactly I could do to copy files from smb to my local drive as I am using linux machine. ``` import tempfile from smb.SMBConnection import SMBConnection from nmb.NetBIOS import NetBIOS conn = SMBConnection('salead', 'repo@2k12', '192.168.14.1', 'SERVER', use_ntlm_v2=True) assert conn.connect('192.168.1.41', 139) if conn: print "successfull",conn else: print "failed to connect" ``` If anyone can help me out it would be a great help for me. Thanks

Original source