Giter Club home page Giter Club logo

easypysmb's Introduction

easysmb

PyPI PyPI - Downloads PyPI - License Python Lint

This library eases the use of pysmb by providing simple functions to do basic stuff.

from easypysmb import EasyPySMB

# Connect
e = EasyPySMB(
    'smbserver.example.com',
    domain='example.com',
    username='me',
    password='PassW0rd'
)

# List files
e.ls('share1/')

# Store files
e.store_file('/tmp/test.txt', 'share1/test.txt')

# Retrieve files
f = e.retrieve_file('share1/text.txt')

# Backup files
e.backup_file('share1/text.txt', 'share2/test.backup.txt')

# mkdir -p
e.mkdir('share1/dir1/dir2/dir3')

# Terminate connection
e.close()

easypysmb's People

Contributors

dependabot[bot] avatar pschmitt avatar pyup-bot avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

easypysmb's Issues

Expose listPath Methode of SMBConnection

Currently it is not possible to use the listPath() Method from the SMBConnection Package. I think this is a important feature of the PYSMB Library as it is used to check if a file already exists on the Destination Server. Please expose it in your Code to vastly improve usability

store_file() throws TypeError exception with Python3 on windows

store_file() leads to "TypeError: can't concat bytes to str" exception in smb\smb2_structs.py.
It looks that opening file_obj in binary mode ('rb') fixes the issue.

--- easypysmb.py	(revision )
+++ easypysmb.py	(revision )
@@ -120,7 +120,7 @@
         assert dest_path, 'Destination path is unset'
         share_name, dest_path = self.__guess_share_name(dest_path, share_name)
         if type(file_obj) is str or type(file_obj) is str:
-            file_obj = open(file_obj)
+            file_obj = open(file_obj, 'rb')
         logger.info(
             'Attempt to store {} on {}:{}'.format(
                 file_obj.name, share_name, dest_path

Full stack trace follows:

Traceback (most recent call last):
File "C:/test/smbcli2.py", line 15, in
z = e.store_file(file_obj='/tmp/body.txt', dest_path='body.txt')
File "C:\Local\Python36\lib\site-packages\easypysmb\easypysmb.py", line 134, in store_file
file_obj
File "C:\Local\Python36\lib\site-packages\smb\SMBConnection.py", line 316, in storeFile
return self.storeFileFromOffset(service_name, path, file_obj, 0, True, timeout)
File "C:\Local\Python36\lib\site-packages\smb\SMBConnection.py", line 347, in storeFileFromOffset
self._pollForNetBIOSPacket(timeout)
File "C:\Local\Python36\lib\site-packages\smb\SMBConnection.py", line 583, in _pollForNetBIOSPacket
self.feedData(data)
File "C:\Local\Python36\lib\site-packages\nmb\base.py", line 54, in feedData
self._processNMBSessionPacket(self.data_nmb)
File "C:\Local\Python36\lib\site-packages\nmb\base.py", line 75, in _processNMBSessionPacket
self.onNMBSessionMessage(packet.flags, packet.data)
File "C:\Local\Python36\lib\site-packages\smb\base.py", line 137, in onNMBSessionMessage
if self._updateState(self.smb_message):
File "C:\Local\Python36\lib\site-packages\smb\base.py", line 276, in _updateState_SMB2
req.callback(message, **req.kwargs)
File "C:\Local\Python36\lib\site-packages\smb\base.py", line 909, in createCB
sendWrite(create_message.tid, create_message.payload.fid, starting_offset)
File "C:\Local\Python36\lib\site-packages\smb\base.py", line 924, in sendWrite
self._sendSMBMessage(m)
File "C:\Local\Python36\lib\site-packages\smb\base.py", line 227, in _sendSMBMessage_SMB2
smb_message.raw_data = smb_message.encode()
File "C:\Local\Python36\lib\site-packages\smb\smb2_structs.py", line 79, in encode
self.payload.prepare(self)
File "C:\Local\Python36\lib\site-packages\smb\smb2_structs.py", line 466, in prepare
self.flags) + self.data
TypeError: can't concat bytes to str

Failed to store binary file to smb

When I try to store a binary file to smb server, such as image.bin, the destination file is a damaged one when smb.store_file completed.

The issue was fixed after I changed the code as below:

def store_file(self, file_obj, dest_path=None, share_name=None, retries=3):
    if not dest_path:
        dest_path = self.file_path
    assert dest_path, 'Destination path is unset'
    share_name, dest_path = self.__guess_share_name(dest_path, share_name)
    if type(file_obj) is str or type(file_obj) is str:

-- file_obj = open(file_obj)
++ file_obj = open(file_obj,'rb')

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.