miketeo/pysmb

retrieveFile doesn't work in functions or class

ricksmith96 opened this issue · 3 comments

When I have it in raw code it work fine

conn = SMBConnection("username", "password", use_ntlm_v2 = True)
assert conn.connect("192.168.0.11", 139)
write = open("download.txt","wb")
conn.retrieveFile("test","test.txt",write)
conn.close()

But when I put in in function it doesn't work

def foo():
    conn = SMBConnection("username", "password", use_ntlm_v2 = True)
    assert conn.connect("192.168.0.11", 139)
    write = open("download.txt","wb")
    conn.retrieveFile("test","file.txt",write)
    conn.close()

foo()

class foo(object):

    def __init__(self):
        conn = SMBConnection("username", "password", use_ntlm_v2 = True)
        assert conn.connect("192.168.0.11", 139)
        write = open("download.txt","wb")
        conn.retrieveFile("test","file.txt",write)
        conn.close()

foo()

It doesn't give me any error but just makes an empty file
If it helps server is ubuntu server and running samba

I'm not able to reproduce your error. All the pysmb's regression tests run in functions, so you have a pretty bizarre situation.

I'm not sure if you have provided the actual code, but you need at least 4 parameters to instantiate a new SMBConnection instance.

SMBConnection("user", "mypassword", "TESTCLIENT", "SERVER", use_ntlm_v2 = True)

This is the full code I was making simple functions for reading and writing to smb server I have reinstalled pysmb and still, it doesn't work

from smb.SMBConnection import SMBConnection

conn = SMBConnection("user", "mypassword", "TESTCLIENT", "SERVER", use_ntlm_v2 = True)
assert conn.connect("192.168.0.11", 139)
def fname():
    write = open("download.txt","wb")
    conn.retrieveFile("test","file.txt",write)

fname()
conn.close()

Problem was with write.close()