miketeo / pysmb

pysmb is an experimental SMB/CIFS library written in Python. It implements the client-side SMB/CIFS protocol (SMB1 and SMB2) which allows your Python application to access and transfer files to/from SMB/CIFS shared folders like your Windows file sharing and Samba folders.
Other
341 stars 94 forks source link

storeFile writing 0 byte files #23

Open siznad opened 10 years ago

siznad commented 10 years ago

I'm using pysmb 1.1.13 with Python 2. I'm using the storeFIle function to copy files to a share. It is writing 0 byte files. The same piece of code works just fine on a different share on a different server.

Here's the code.

from smb.SMBConnection import SMBConnection from smb import smb_structs smb_structs.SUPPORT_SMB2 = False

client_machine_name = 'TESTPC' server_name = 'testsvr' server_ip = 'testsvr' username = 'bob' password = 'password' inputfile = 'text.txt'

conn = SMBConnection(username, password, client_machine_name, server_name, use_ntlm_v2 = True)

conn.connect(server_ip, 139)

with open(inputfile, 'r') as file_obj: numBytes = conn.storeFile('workgroup', 'testpath', file_obj, timeout=600)

conn.close()

Not sure what is different about each share that one would result in 0 byte files. Any ideas on how to troubleshoot this?

miketeo commented 10 years ago

@siznad : Can you provide more information about the remote server? What are the versions of the OS/Samba service that is working and is not working?

If you can, please provide the TCP packet capture of both working and non-working scenarios.

Thank you

siznad commented 10 years ago

Hi Michael,

Thanks for the quick response. I don't have the details yet about the remote servers. I can get that next week. But I did already take network captures for both scenarios.

Attached are the working and non-working captures.

For the not working scenario use filter 'tcp.stream eq 0'

For working, use filter 'tcp.stream eq 110'

Thanks.

On 2014-10-25 13:44, Michael Teo wrote:

@siznad [1] : Can you provide more information about the remote server? What are the versions of the OS/Samba service that is working and is not working?

If you can, please provide the TCP packet capture of both working and non-working scenarios.

Thank you

Reply to this email directly or view it on GitHub [2].

Links:

[1] https://github.com/siznad [2] https://github.com/miketeo/pysmb/issues/23#issuecomment-60492929

miketeo commented 10 years ago

@siznad : I think the attachments are not available on github when you reply via email. Can you email me your packet captures directly at miketeo@miketeo.net ? Thanks

siznad commented 10 years ago

Hi, I sent you the captures to miketeo@miketeo.net. Just wanted to confirm you got them. John

miketeo commented 10 years ago

Thank goodness you have probed me on this. Your packet capture has ended up in my spam box. I will look into this.

miketeo commented 10 years ago

@siznad : I was looking through your packet captures. The remote CIFS/SMB server for the non-working looks interesting; it seems to be a NAS. Can you provide more details on the remote server? Thank you.

siznad commented 10 years ago

It is NAS. It's a SAN storage running NetApp.

siznad commented 9 years ago

Hi Mike,

Any idea what the issue could be?

John

miketeo commented 9 years ago

@siznad: Unfortunately, I do not have access to a NetApp storage facility to troubleshoot. I'm tied down with my work for this month, and will look into this once my time loosen up.

joselitosn commented 9 years ago

@miketeo @siznad Don't know if this is already solved, but using is_direct_tcp=True on the SMBConnection solved the problem for me. Also, you might wanna use port 445 instead of 139.

G-Goldstein commented 8 years ago

I had the same symptom and in my case it was because the opened file was positioned to the end of the file. The storeFile method just performs read() to get the data, so it wasn't finding anything at the end of the file. I did a file_obj.seek(0) before writing and this fixed it.

zrachlin commented 3 years ago

@G-Goldstein 6 years later, thank you so much for this! Saved me.