1

I am trying to retrieve a file on a network location - actually a NAS with fixed IP address.

Using File.Exists(@"//myserver/myfile.txt") works just fine, unfortunately, File.Exists(@"//192.168.1.101/myfile.txt") doesn't (of course, I made sure ping myserver returns 192.168.1.101).

I couldn't find any reasonable explanation as to why using DNS names would work but not IP address. Is this a known issue or is it possibly an issue with my network? I'd really get it to work with IP address, but is it possible?

neggenbe
  • 1,697
  • 2
  • 24
  • 62
  • 2
    Should't there be a share on the nas where the file is located? Eg: `File.Exists(@"\\192.168.1.101\NASShare\myfile.txt")` – Rawns Mar 10 '17 at 14:15
  • One could easily imagine that it may be possible for a single host to pretend to be multiple independent hosts and to be using the hostname to distinguish requests (in the way that a single webserver can host multiple domain's websites). Why do you want/need to use IP access since you know that hostname access works? – Damien_The_Unbeliever Mar 10 '17 at 14:15
  • @Damien_The_Unbeliever I do in my test environment. Unfortunately, I am not managing networks for all my customers, which use a share via IP and not domain name... – neggenbe Mar 10 '17 at 14:17
  • @GrantWinney `File.Open` returns `The user name or password is incorrect.`. Strange as I can access via Explorer without password... – neggenbe Mar 10 '17 at 14:21
  • On my server I did something similar, but as it was windows I created a virtual mapping on windows and instead of accessing the network address directly access a mapped disk drive, so I had no problem with access credentials. – Nilber Vittorazzi Mar 10 '17 at 14:40
  • You can try use FileWebRequest for load remote file. In my local network it`s work successfully: http://stackoverflow.com/questions/2471209/how-to-read-a-file-from-internet – Ivan Kishchenko Mar 10 '17 at 14:53
  • @NilberVittorazzi Yes that could be an option, but then, I need to map network drives on all computers with the same drive name... The good thing about IP (as it is fixed) is that it is independent of the computer on which I run the script... As with mapped network drives, it gets shaky if I use "Z" instead of "Y"... – neggenbe Mar 10 '17 at 14:54

0 Answers0