jborean93 / smbprotocol

Python SMBv2 and v3 Client
MIT License
318 stars 73 forks source link

value err, kindly advice #179

Closed doitAx2 closed 2 years ago

doitAx2 commented 2 years ago

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")

jborean93 commented 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.

doitAx2 commented 2 years ago

src = testfolder_rec in local dest = "\domain.com\ex\extension2\extension3\extension4"

doitAx2 commented 2 years ago

thanks alot for the swift help

jborean93 commented 2 years ago

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.

doitAx2 commented 2 years ago

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"

jborean93 commented 2 years ago

You need it to start with 2 backslashes, UNC paths are in the format \\server\share\....

doitAx2 commented 2 years ago

so sorry I did start with that dest = r"\domain.com\ex\extension2\extension2\extension4" didnt copy correctly

doitAx2 commented 2 years ago
Screen Shot 2022-05-25 at 8 22 16 PM
jborean93 commented 2 years ago

Your path only contains the server name, you also need to specify the share.

doitAx2 commented 2 years ago
Screen Shot 2022-05-25 at 8 26 14 PM
jborean93 commented 2 years ago

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.

doitAx2 commented 2 years ago

sorry I just blurred it all at once

jborean93 commented 2 years ago

Try using an absolute path for the src, maybe it's thinking that's also a UNC path but not.

doitAx2 commented 2 years ago

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

jborean93 commented 2 years ago

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.

doitAx2 commented 2 years ago

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

doitAx2 commented 2 years ago

and the write_path uses the r'\\

jborean93 commented 2 years ago

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.

doitAx2 commented 2 years ago

I see, I can help to contribute the change for that support how shall it be done ?

jborean93 commented 2 years ago

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.