Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read/Writing files in node with fs via UNC path

Tags:

node.js

fs

unc

Having issues of reading/writing to a UNC path with nodeJs on my local machine. At one point fs was read/writing from my machine to the UNC path just fine, but now it appears that it cannot read/write to it.

UNC Path : \\[machine name]\folder1\folder2\file.csv

I upgraded to node version 12 awhile back and thought perhaps there is a network path bug, but not seeing anyone online affected. I then used nvmw to load an older version of node and still nothing.

I wondered if it was because I was not joined to the same domain, however, that was not an issue before. I can ping the box, access in windows explorer, remote in.

I have tried running my app as my user, as admin, added a windows credential for network admin in credential manager.

Tried changing the flags used for permissions r, r+, a, a+ 0666...

Paths Tried

  • \\[machine name]\
  • \\?\[machine name]\
  • \\?\UNC\[machine name]\

Write Error

{ 
  [Error: UNKNOWN, mkdir '\\[machine name]\Storage\CSV\Example.csv']
  errno: -4094,
  code: 'UNKNOWN',
  path: '\\[machine name]\Storage\CSV\Example.csv' 
}

Read Error

{ 
  [Error: UNKNOWN, open '\\[machine name]\Storage\CSV\Example.csv']
  errno: -4094,
  code: 'UNKNOWN',
  path: '\\[machine name]\Storage\CSV\Example.csv' 
}

I have walked through a lot of the actual fs code and it seems to ultimately generate the appropriate path but doesnt seem to vibe well with the windows for accessing the UNC path.

I am hoping someone can give me a few pointers of things to check or possible reasons for this.

like image 389
afreeland Avatar asked Apr 02 '15 13:04

afreeland


1 Answers

As you know in node, the backslash is the escape character, so you will need to double the number of backslashes you use. For:

\\machine name\folder1\folder2\filename.ext

try:

\\\\machine name\\folder1\\folder2\\filename.ext
like image 125
Anthony S Avatar answered Oct 27 '22 01:10

Anthony S