I am using smb.SMBConnection from pysmb
package to fetch files from Share hosted on Windows to Linux Host. Script is run on Linux and it works with simple files like follows:
from smb.SMBConnection import SMBConnection
conn = SMBConnection(
username, password, server, domain, use_ntlm_v2=True,
sign_options=SMBConnection.SIGN_WHEN_SUPPORTED,
is_direct_tcp=True
)
conn.connect(server, 445)
file_attributes, filesize = conn.retrieveFile(share_name + "/" + filename, local_file)
Is there a way to make this code work, when filename
and local_file
are directories?
Just attempting the same code on directory will plainly fail:
File "/usr/lib/python3.6/site-packages/smb/SMBConnection.py", line 341, in eb
raise failure
smb.smb_structs.OperationFailure: Failed to retrieve on 1.7.3: Unable to open file
==================== SMB Message 0 ====================
SMB Header:
-----------
Command: 0x03 (SMB2_COM_TREE_CONNECT)
Status: 0x00000000
Flags: 0x08
PID: 12815
MID: 3
TID: 0
Data: 42 bytes
b'09...'
SMB Data Packet (hex):
----------------------
b'fe5...'
How to fetch entire directory (rather than single file) from Windows Share to Linux Host, using Python?
User contributions licensed under CC BY-SA 3.0