Comments (14)
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.
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.
@alexei : Have you tried createDirectory('myshare', 'a/b') ?
from pysmb.
Yes.
client.createDirectory('myshare', 'foo/bar')
results in smb.smb_structs.OperationFailure: Failed to create directory foo\bar on myshare: Create failed
from pysmb.
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.
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.
@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.
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.
@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.
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.
I have the same issue. Can you discribe your solution? thx so much.
from pysmb.
Note that if you are trying to create 'foo/bar' folder, 'foo' folder must exist on the remote server.
from pysmb.
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.
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)
- Cant connect w/ smb on mac os, python 3.8 HOT 6
- Can't get file list on DFS shared folder HOT 6
- listPath fails with "STATUS_ACCESS_DENIED" due to too broad access mask HOT 2
- pysmb-provided MD4 implementation for Python3 is broken HOT 6
- ThreadPoolExecutor storeFile HOT 1
- Using same code in Windows and Linux to access remote paths HOT 2
- Problem performing listPath using SMB1 with version 1.2.8 (similar to issue #195)
- Server does not support any of the pysmb dialects HOT 2
- When are compressed transfers supported?
- Unable to install the latest version of pysmb(1.2.9) HOT 7
- TypeError: can't concat str to bytes HOT 2
- How to improve transfer speed
- Server does not support any of the pysmb dialects. Please email pysmb to add in support for your OS HOT 1
- Copy a file using pysmb from windows to linux HOT 8
- Don't connect to SMBv2 server HOT 5
- Provide wheel distributions
- Using Chunk? HOT 5
- Request to Update Documentation for SMBConnection Class HOT 4
- storeFile raise SMBTimeout exception on files > 1k HOT 2
- Compatibility Issue with Unraid SMB Server: Unable to Negotiate Supported SMB Dialect
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pysmb.