miketeo/pysmb

storeFile from subFolders Unable to open file

PeroPonneso opened this issue · 2 comments

Hi,
thanks for pysmb, it is a nice tool.

I'm running the code from a folder in Windows Server 2019 (also from Windows 10) to a share on Linux 20.04.

When i transfer a file in the same folder as the code to the share the operation is completed successfully

path = ""

print('direzione:  da', myname, 'a', ip)

conn = SMBConnection(user, pw, myname, srv, use_ntlm_v2 = True)
assert conn.connect(ip, port=139)

print('connessione:', ' instaurata')

#file from local to share(Windows LOC -> RM Linux)
filenames = glob.glob("*.png")
elts = len(filenames)
print('file trovati: ', elts)

print('writing: ', 'started')
for i,f in enumerate(filenames):
    sys.stdout.write('\r')
    with open(f,"rb") as file2transfer:
        conn.storeFile(share,path + f, file2transfer, timeout=30 )
        file2transfer.close()

print('writing: ', 'completed')

conn.close()

Now i need to send a bunch of files from different folders to the same share.
To achieve that i tried modifying the writing part like this :

path = "branch1\\"

#file from local to share(Windows LOC -> RM Linux)
f= "file1.png"

print('writing: ', 'started')
  with open(path+f,"rb") as file2transfer:
      conn.storeFile(share, path + f, file2transfer, timeout=30 )
      file2transfer.close()

print('writing: ', 'completed')

the open() function gives back the right name and doesn't throw exception;
the conn.storeFile() throws:

OperationFailure: Failed to store branch1\file1.png on LinuxShare: Unable to open file
==================== SMB Message 0 ====================
SMB Header:
-----------
Command: 0x03 (SMB2_COM_TREE_CONNECT) 
Status: 0x00000000 
Flags: 0x00 
PID: 18044 
MID: 3 
TID: 0 
Data: 48 bytes 
b'09000000480028005c005c004c0045004d0050002d0056004d005c004c0069006e007500780053006800610072006500' 
SMB Data Packet (hex):
----------------------
b'fe534d42400000000000000003000000000000000000000003000000000000007c4600000000000012e56d56000000000000000000000000000000000000000009000000480028005c005c004c0045004d0050002d0056004d005c004c0069006e007500780053006800610072006500'
==================== SMB Message 1 ====================
SMB Header:
-----------
Command: 0x03 (SMB2_COM_TREE_CONNECT) 
Status: 0x00000000 
Flags: 0x01 
PID: 18044 
MID: 3 
TID: 1161377897 
Data: 16 bytes 
b'100001000000000000000000ff011f10' 
SMB Data Packet (hex):
----------------------
b'fe534d42400000000000000003000100010000000000000003000000000000007c4600006938394512e56d560000000000000000000000000000000000000000100001000000000000000000ff011f10'
==================== SMB Message 2 ====================
SMB Header:
-----------
Command: 0x05 (SMB2_COM_CREATE) 
Status: 0x00000000 
Flags: 0x00 
PID: 18044 
MID: 4 
TID: 1161377897 
Data: 232 bytes 
b'3900000002000000000000000000000000000000000000009f0112002000000000000000050000004400000078003200b0000000780000006200720061006e006300680031005c006200720061006e006300680031005f00660069006c00650031002e0070006e0067000000000000002800000010000400000018001000000044486e51000000000000000000000000000000000000000020000000100004000000180008000000416c5369000000008562000000000000180000001000040000001800000000004d78416300000000000000001000040000001800000000005146696400000000' 
SMB Data Packet (hex):
----------------------
b'fe534d42400000000000000005000000000000000000000004000000000000007c4600006938394512e56d5600000000000000000000000000000000000000003900000002000000000000000000000000000000000000009f0112002000000000000000050000004400000078003200b0000000780000006200720061006e006300680031005c006200720061006e006300680031005f00660069006c00650031002e0070006e0067000000000000002800000010000400000018001000000044486e51000000000000000000000000000000000000000020000000100004000000180008000000416c5369000000008562000000000000180000001000040000001800000000004d78416300000000000000001000040000001800000000005146696400000000'
==================== SMB Message 3 ====================
SMB Header:
-----------
Command: 0x05 (SMB2_COM_CREATE) 
Status: 0xC000003A 
Flags: 0x01 
PID: 18044 
MID: 4 
TID: 1161377897 
Data: 9 bytes 
b'090000000000000000' 
SMB Data Packet (hex):
----------------------
b'fe534d42400000003a0000c005000100010000000000000004000000000000007c4600006938394512e56d560000000000000000000000000000000000000000090000000000000000'

I've tried different combinations of path and filename using "\" , "/", "./" and ".\" but it doesn't solve the problem.
Am i missing something or misunderstanding how i should format the function for files in different locations?

Thanks

Is branch1 created and writable by the user on the remote server?

Thanks for the attention @miketeo,

If branch1 is already present in the remote and the local (with correct authorizations) with the same relative path configuration it works. I wanted to grab files from, lets say:

from Windows:
root\branch1\file1
root\branch2\file2
root\branch3\file3
...

to Linux:
root\files\file1
root\files\file2
root\files\file3
...

having a different folder configuration between the two.
I'm quite sure i'm just using the store function badly.

Thanks again for the reply