Giter Club home page Giter Club logo

Comments (14)

alexei avatar alexei commented on June 6, 2024

I am able to create directories with createDirectory, but there's no way to either create a subdirectory or change the cwd to another directory.

from pysmb.

alexei avatar alexei commented on June 6, 2024

After a few more tests I realiezed I can simply create a directory "a", then another "b", and then rename "b" to "a/b". That seems to do the trick.

Is this the only way?

from pysmb.

miketeo avatar miketeo commented on June 6, 2024

@alexei : Have you tried createDirectory('myshare', 'a/b') ?

from pysmb.

alexei avatar alexei commented on June 6, 2024

Yes.
client.createDirectory('myshare', 'foo/bar') results in smb.smb_structs.OperationFailure: Failed to create directory foo\bar on myshare: Create failed

from pysmb.

miketeo avatar miketeo commented on June 6, 2024

What OS/distro are you using?
If you can provide the packet capture, I can look into this in more details later on.

from pysmb.

alexei avatar alexei commented on June 6, 2024

I'm on Ubuntu 14.04 x86-64, Python 2.7, pysmb 1.1.12

Here's the code:

client = SMBConnection(smb_username, smb_password, client_ip, smb_server_name, use_ntlm_v2=True)
client.connect(smb_server_ip, smb_port)
client.createDirectory(smb_folder, 'foo/bar')

And the output:

Traceback (most recent call last):
  File "test.py", line 58, in <module>
    client.createDirectory(smb_folder, 'foo/bar')
  File "[...]/local/lib/python2.7/site-packages/smb/SMBConnection.py", line 391, in createDirectory
    self._pollForNetBIOSPacket(timeout)
  File "[...]/local/lib/python2.7/site-packages/smb/SMBConnection.py", line 538, in _pollForNetBIOSPacket
    self.feedData(data)
  File "[...]/local/lib/python2.7/site-packages/nmb/base.py", line 54, in feedData
    self._processNMBSessionPacket(self.data_nmb)
  File "[...]/local/lib/python2.7/site-packages/nmb/base.py", line 75, in _processNMBSessionPacket
    self.onNMBSessionMessage(packet.flags, packet.data)
  File "[...]/local/lib/python2.7/site-packages/smb/base.py", line 143, in onNMBSessionMessage
    if self._updateState(self.smb_message):
  File "[...]/local/lib/python2.7/site-packages/smb/base.py", line 1513, in _updateState_SMB1
    req.callback(message, **req.kwargs)
  File "[...]/local/lib/python2.7/site-packages/smb/base.py", line 2234, in createCB
    errback(OperationFailure('Failed to create directory %s on %s: Create failed' % ( path, service_name ), messages_history))
  File "[...]/local/lib/python2.7/site-packages/smb/SMBConnection.py", line 385, in eb
    raise failure
smb.smb_structs.OperationFailure: Failed to create directory foo\bar on x: Create failed
==================== SMB Message 0 ====================
SMB Header:
-----------
Command: 0x75 (SMB_COM_TREE_CONNECT_ANDX) 
Status: NTSTATUS=0x00000000 
Flags: 0x18 
Flags2: 0xC807 
PID: 8949 
UID: 100 
MID: 4 
TID: 0 
Security: 0x0000000000000000 
Parameters: 8 bytes 
ff0000000c000100 
Data: 25 bytes 
005c005c005a004500550053005c00780000003f3f3f3f3f00 
SMB Data Packet (hex):
----------------------
ff534d4275000000001807c80000000000000000000000000000f5226400040004ff0000000c0001001900005c005c005a004500550053005c00780000003f3f3f3f3f00
==================== SMB Message 1 ====================
SMB Header:
-----------
Command: 0x75 (SMB_COM_TREE_CONNECT_ANDX) 
Status: NTSTATUS=0x00000000 
Flags: 0x88 
Flags2: 0xC803 
PID: 8949 
UID: 100 
MID: 4 
TID: 1 
Security: 0x0000000000000000 
Parameters: 14 bytes 
ff0000000100ff011f0000000000 
Data: 13 bytes 
413a004e005400460053000000 
SMB Data Packet (hex):
----------------------
ff534d4275000000008803c80000000000000000000000000100f5226400040007ff0000000100ff011f00000000000d00413a004e005400460053000000
==================== SMB Message 2 ====================
SMB Header:
-----------
Command: 0x00 (SMB_COM_CREATE_DIRECTORY) 
Status: NTSTATUS=0x00000000 
Flags: 0x18 
Flags2: 0xC807 
PID: 8949 
UID: 100 
MID: 5 
TID: 1 
Security: 0x0000000000000000 
Parameters: 0 bytes 

Data: 17 bytes 
0466006f006f005c006200610072000000 
SMB Data Packet (hex):
----------------------
ff534d4200000000001807c80000000000000000000000000100f522640005000011000466006f006f005c006200610072000000
==================== SMB Message 3 ====================
SMB Header:
-----------
Command: 0x00 (SMB_COM_CREATE_DIRECTORY) 
Status: NTSTATUS=0xC000003A 
Flags: 0x88 
Flags2: 0xC803 
PID: 8949 
UID: 100 
MID: 5 
TID: 1 
Security: 0x0000000000000000 
Parameters: 0 bytes 

Data: 0 bytes 

SMB Data Packet (hex):
----------------------
ff534d42003a0000c08803c80000000000000000000000000100f52264000500000000

from pysmb.

miketeo avatar miketeo commented on June 6, 2024

@alexei : Weird, I'm not able to reproduce the error. Are you using Ubuntu 14.04 as your remote server? I will need the packet capture from you to see what's wrong with the communication on your end.

from smb.SMBConnection import SMBConnection

c = SMBConnection('mike', 'xyzpass', 'MYTEST', 'TESTSERVER')
c.connect('127.0.0.1')
c.createDirectory('smbtest','foo')
c.createDirectory('smbtest','foo/bar')

from pysmb.

alexei avatar alexei commented on June 6, 2024

Hello,

The file server is a Samba 3.5.8, and runs on Ubuntu 11.04 x86_64 (Linux 2.6.38-16).

HTH

from pysmb.

sevenjay avatar sevenjay commented on June 6, 2024

@miketeo : I have the same issue.
Samba Server: 4.1.6-Ubuntu on Ubuntu 14.04 x86_64
Client: both python 3.4.3 and 3.5.1, pysmb-1.1.17 on Ubuntu 14.04 x86_64
thx

from pysmb.

keeely avatar keeely commented on June 6, 2024

I tried this with python 2.7.8 (win, 32-bit), pysmb 1.1.18, samba 4.1, no issues. The full Samba config is the same as in my post here

from pysmb.

jingjing0506 avatar jingjing0506 commented on June 6, 2024

I have the same issue. Can you discribe your solution? thx so much.

from pysmb.

miketeo avatar miketeo commented on June 6, 2024

Note that if you are trying to create 'foo/bar' folder, 'foo' folder must exist on the remote server.

from pysmb.

jingjing0506 avatar jingjing0506 commented on June 6, 2024

Note that if you are trying to create 'foo/bar' folder, 'foo' folder must exist on the remote server.

It works when I add Samba config
create mask = 0666
directory mask = 0777

from pysmb.

FengZhiheng avatar FengZhiheng commented on June 6, 2024

I'm on Ubuntu 14.04 x86-64, Python 2.7, pysmb 1.1.12

Here's the code:

client = SMBConnection(smb_username, smb_password, client_ip, smb_server_name, use_ntlm_v2=True)
client.connect(smb_server_ip, smb_port)
client.createDirectory(smb_folder, 'foo/bar')

And the output:

Traceback (most recent call last):
  File "test.py", line 58, in <module>
    client.createDirectory(smb_folder, 'foo/bar')
  File "[...]/local/lib/python2.7/site-packages/smb/SMBConnection.py", line 391, in createDirectory
    self._pollForNetBIOSPacket(timeout)
  File "[...]/local/lib/python2.7/site-packages/smb/SMBConnection.py", line 538, in _pollForNetBIOSPacket
    self.feedData(data)
  File "[...]/local/lib/python2.7/site-packages/nmb/base.py", line 54, in feedData
    self._processNMBSessionPacket(self.data_nmb)
  File "[...]/local/lib/python2.7/site-packages/nmb/base.py", line 75, in _processNMBSessionPacket
    self.onNMBSessionMessage(packet.flags, packet.data)
  File "[...]/local/lib/python2.7/site-packages/smb/base.py", line 143, in onNMBSessionMessage
    if self._updateState(self.smb_message):
  File "[...]/local/lib/python2.7/site-packages/smb/base.py", line 1513, in _updateState_SMB1
    req.callback(message, **req.kwargs)
  File "[...]/local/lib/python2.7/site-packages/smb/base.py", line 2234, in createCB
    errback(OperationFailure('Failed to create directory %s on %s: Create failed' % ( path, service_name ), messages_history))
  File "[...]/local/lib/python2.7/site-packages/smb/SMBConnection.py", line 385, in eb
    raise failure
smb.smb_structs.OperationFailure: Failed to create directory foo\bar on x: Create failed
==================== SMB Message 0 ====================
SMB Header:
-----------
Command: 0x75 (SMB_COM_TREE_CONNECT_ANDX) 
Status: NTSTATUS=0x00000000 
Flags: 0x18 
Flags2: 0xC807 
PID: 8949 
UID: 100 
MID: 4 
TID: 0 
Security: 0x0000000000000000 
Parameters: 8 bytes 
ff0000000c000100 
Data: 25 bytes 
005c005c005a004500550053005c00780000003f3f3f3f3f00 
SMB Data Packet (hex):
----------------------
ff534d4275000000001807c80000000000000000000000000000f5226400040004ff0000000c0001001900005c005c005a004500550053005c00780000003f3f3f3f3f00
==================== SMB Message 1 ====================
SMB Header:
-----------
Command: 0x75 (SMB_COM_TREE_CONNECT_ANDX) 
Status: NTSTATUS=0x00000000 
Flags: 0x88 
Flags2: 0xC803 
PID: 8949 
UID: 100 
MID: 4 
TID: 1 
Security: 0x0000000000000000 
Parameters: 14 bytes 
ff0000000100ff011f0000000000 
Data: 13 bytes 
413a004e005400460053000000 
SMB Data Packet (hex):
----------------------
ff534d4275000000008803c80000000000000000000000000100f5226400040007ff0000000100ff011f00000000000d00413a004e005400460053000000
==================== SMB Message 2 ====================
SMB Header:
-----------
Command: 0x00 (SMB_COM_CREATE_DIRECTORY) 
Status: NTSTATUS=0x00000000 
Flags: 0x18 
Flags2: 0xC807 
PID: 8949 
UID: 100 
MID: 5 
TID: 1 
Security: 0x0000000000000000 
Parameters: 0 bytes 

Data: 17 bytes 
0466006f006f005c006200610072000000 
SMB Data Packet (hex):
----------------------
ff534d4200000000001807c80000000000000000000000000100f522640005000011000466006f006f005c006200610072000000
==================== SMB Message 3 ====================
SMB Header:
-----------
Command: 0x00 (SMB_COM_CREATE_DIRECTORY) 
Status: NTSTATUS=0xC000003A 
Flags: 0x88 
Flags2: 0xC803 
PID: 8949 
UID: 100 
MID: 5 
TID: 1 
Security: 0x0000000000000000 
Parameters: 0 bytes 

Data: 0 bytes 

SMB Data Packet (hex):
----------------------
ff534d42003a0000c08803c80000000000000000000000000100f52264000500000000

I had the same problem, so I came up with a solution:

relativePath = r'\\a\\b\\c\\d'
tt = relativePath.split("\\")
for i in range(len(tt)+1):
    tempDir = []
    for j in range(i):
        tempDir.append(tt[j])
        tempDir.append("/")
    tempDir2 = ''.join(tempDir)
    try:
        self.samba.createDirectory(self.service_name, self.smb_dir + tempDir2)  # 先创建文件夹
    except:
        pass

from pysmb.

Related Issues (20)

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.