Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getFile in a remote folder doesn't appear to work #24

Closed
jmaton opened this issue Jun 16, 2020 · 5 comments
Closed

getFile in a remote folder doesn't appear to work #24

jmaton opened this issue Jun 16, 2020 · 5 comments

Comments

@jmaton
Copy link
Contributor

jmaton commented Jun 16, 2020

First and foremost, thank you very much for this library! :-)

Consider, the address is: \\theaddress\myshare
Inside that there is a folder named "foo", and in the foo folder there is a file "bar".

I want that file so I do this:

let client = new SambaClient('\\\\theaddress\\myshare, 'myuser', 'mypass', '', 'SMB3');
client.getFile('foo/bar', 'localbar);

This fails with an ENOENT. The command it's running is actually:
smbclient -U 'myuser' -c 'get bar localbar' //theaddress/myshare 'mypass' --max-protocol SMB3

i.e., it strips the folder.

This is due to the code in "runCommand"; it interprets the remote folder as the local working directory:

runCommand(cmd, path, destination) {
    let workingDir = p.dirname(path);
    let fileName = p.basename(path).replace(singleSlash, '\\');
    let cmdArgs = util.format('%s %s', fileName, destination);

    return this.execute(cmd, cmdArgs, workingDir);
  }

I tweaked getFile and sendFile slightly (and deleted runCommand) :

  getFile(path, destination, workingDir) {
    let fileName = path.replace(singleSlash, '\\');
    let cmdArgs = util.format('%s %s', fileName, destination);
    return this.execute('get', cmdArgs, workingDir);
  }

  sendFile(path, destination) {
    let workingDir = p.dirname(path);
    let fileName = p.basename(path).replace(singleSlash, '\\');
    let cmdArgs = util.format('%s %s', fileName, destination.replace(singleSlash, '\\'));
    return this.execute('put', cmdArgs, workingDir);
  }

also in function "execute" I tweaked this line based on the pull request #20

    let options = {
      cwd: (workingDir ? workingDir : '')
    };

May I check in these fixes?

Again, thank you for this library.

@jakesjews
Copy link
Member

@jmaton no problem. A PR would be awesome thanks!

@secolinsky
Copy link

secolinsky commented Aug 12, 2020

jmaton, thanks for this post. I was having similar problems on my ubuntu machine getting the file from the samba server, with node giving an ENOENT error. Your changes to the getFile fixed my problem.

I was having trouble understanding why the code needs a wrap function. It seem's a bit peculiar. Either way, it's needed because it can't work if I take the wrap out.

Also, when I used the provided code to then find the promise had been fulfilled with an error that was caught in a catch clause, I couldn't make sense of the spawnargs and cmd properties. Below I share the values of those two properties:

spawnargs:
   [ '-c',
     'smbclient -U \'un\' -c \'get 20161101_180213.jpg ABSOLUTE_PATH_OF_practice.jpg\' //[INTERNAL_NETWORK_IP]/public \'pw\' -W WORKGROUP' ],
  cmd:
   'smbclient -U \'un\' -c \'get 20161101_180213.jpg /ABSOLUTE_PATH_OF_practice.jpg\' //INTERNAL_NETWORK_IP/public \'pw\' -W WORKGROUP'

I find it hard to read when the values of the command options all start with a backslash.

In the SambaClient options, I write the address as //[INTERNAL_NETWORK_IP]//folder and it works. Also don't need the getFile to have a workingDirectory. I think it's fine with just the two arguments of path and destination.

@jmaton
Copy link
Contributor Author

jmaton commented Nov 29, 2020

I forked, pushed, and created a pull request. Thanks again for such a wonderful library.

@nateevans
Copy link

fixed in #27

@thault
Copy link

thault commented Jul 31, 2023

This seems to have reared up again, I'm trying to send a file from the tmp folder and it's stripping out the folder.
await client.sendFile('/tmp/c023dc82-d4fd-4bd8-a5ee-619f73104bf9.jpg', '\\testimage.jpg');
Shows up in logs:
-c put \"c023dc82-d4fd-4bd8-a5ee-619f73104bf9.jpg\" \"\\testimage.jpg\"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants