Closed doitAx2 closed 2 years ago
Can you share the value for src
and dest
. It sounds like the path isn't in the format that's expected.
src = testfolder_rec in local dest = "\domain.com\ex\extension2\extension3\extension4"
thanks alot for the swift help
You have backslashes in your path but they aren't escaped. You also need to make sure the dest path starts with 2 \
. This can be done in 2 ways
dest = "\\\\domain.com\\ex\\extension2\\extension3\\extension4"
dest = r"\\domain.com\ex\extension2\extension2\extension4"
The first example just makes sure all backslashes are escaped, the 2nd example uses the r
string prefix to ensure you don't need to escape it.
still getting the same issue ValueError: The SMB path specified must contain the server and share to connect to despite using dest = r"\domain.com\ex\extension2\extension2\extension4"
You need it to start with 2 backslashes, UNC paths are in the format \\server\share\...
.
so sorry I did start with that dest = r"\domain.com\ex\extension2\extension2\extension4" didnt copy correctly
Your path only contains the server name, you also need to specify the share.
Your screenshot shows it does not, it's \\something.com\
. It needs to be \\server\share
and any remaining paths after that in the share.
sorry I just blurred it all at once
Try using an absolute path for the src, maybe it's thinking that's also a UNC path but not.
after adding the absolute path I am getting
raise ValueError("Failed to connect to '%s:%s': %s" % (self.server, self.port, str(err))) from err ValueError: Failed to connect to 'Users:445': [Errno 8] nodename nor servname provided, or not known
It's unfortunately hard to tell with the blanked out information but essentially you want something like
import smbclient.shutil
src = '/home/user/path/to/local/dir'
dst = r'\\server\share\path\to\dest\dir'
smbclient.shutil.copytree(src, dst, username='...', password='...')
Make sure your local path starts with a single /
and not 2. Make sure your UNC path starts with 2 \\
and not 1.
I am following the exact format but not having luck
copytree('/Users/******/Documents/playground/testfolder_rec',write_path, username="****",password="*****")
keep getting
self.transport.connect() File "/usr/local/lib/python3.9/site-packages/smbprotocol/transport.py", line 69, in connect raise ValueError("Failed to connect to '%s:%s': %s" % (self.server, self.port, str(err))) from err ValueError: Failed to connect to 'Users:445': [Errno 8] nodename nor servname provided, or not known
and the write_path uses the r'\\
Ah my apologies, currently copytree
does not support remote to local and vice versa https://github.com/jborean93/smbprotocol/blob/3eadf5fdb788d0debef56bac0f3f7c635b9c7384/smbclient/shutil.py#L301
In this current form, copytree() only supports remote to remote copies over SMB.
That's why it's trying to connect to your local path through SMB. Unfortunately this isn't a feature that's currently supported.
I see, I can help to contribute the change for that support how shall it be done ?
You would have to implement the code required in smbclient.shutil
for this function. This is a pretty decent chunk of work to get done properly. If you do wish to try and implement you will have to make the changes and write some tests for it that passes CI when submitting your PR.
Closing this in favour of https://github.com/jborean93/smbprotocol/issues/36 which is the original request for this feature.
when using the copytree I keep getting ValueError: The SMB path specified must contain the server and share to connect to I am using it copytree(src,dest, username="xyz", password="abc")