I wrote a quick console app in VS2010 to copy a file from a network location to a specified location on disk. The program works fine on Windows but when I copy it into the Mac and execute it against the Mono runtime, it seems to have trouble opening the network share.
My code to create a DirectoryInfo object looks like this:
var dir = new DirectoryInfo(#"\\nameofserver\location\to\file");
In Windows, this resolves correctly to the network share. In Mac, it gives me a relative path to the binary (I was running it from the Desktop):
/Users/username/Desktop/\\nameofserver\location\to\file
I did Google it a little bit and it suggested that my path should be of the form smb://.... However, even when I do this, my DirectoryInfo resolves to:
/Users/username/Desktop/smb://nameofserver/location/to/file
I'm guessing there is either a syntax I'm missing to be able to get access to the network share or that it isn't so straightforward on OSX. Either way, I'd like to know how to connect to the network share and download the file.
Thanks!
EDIT:
I tried //nameofserver/location/to/file. This helped somewhat, except that it still did not resolve the network share reference, instead assuming the path to be a local one:
/nameofserver/location/to/file
Related
I'm currently developing on macOS High Sierra (not Windows) using Qt. Just using regular macOS rather than macOS server. I'm happy to write Mac-only code outside the Qt bubble to fix this problem, obviously.
I'm looking for a way to programmatically check in C/C++ or Objective-C whether a particular local folder is shared on the local network. Alternatively I'd like to retrieve a list of all shared folders. I'd like the method to work on a reasonably large range of macOS versions e.g. 10.9 to 10.14.
I need to do this in order to rewrite paths to local files as UNC paths so that they are accessible from a Windows client machine on the same network via SMB sharing with suitable credentials. This does assume shared folders have already been setup but if they haven't the user will receive an error and be prompted to share suitable folders.
I can share/un-share and see the sharing status of a folder using the Get Info dialog in Finder but I'm looking for something I can use within an application.
Things I've tried without success:
Searching for other instances of the problem
NSURL class - doesn't document a resource name to query for its sharing status.
smbutil doesn't seem to list shares being shared from the machine it's running on.
smbd doesn't seem to have any command line options to query shared folders.
The various configuration files mentioned in the smbutil and smbd.conf man pages don't contain a list of shared folders
mdls doesn't contain any relevant metadata in the output for folders that are shared.
ls -l# doesn't list any extra information for shared folders
Sharing an unusually named folder and greping the hard disk for the folder name including binary files to see if this information is persisted somewhere. Presumably it is persisted somehow because the folder is shared after rebooting but I can't find any record of the folder name anywhere.
OpenDirectory services seem to contain lots of references to SMB in the headers but I can't see a way to use OpenDirectory to get a list of folders shared from the local machine.
Sharing the root folder so that the rewriting is trivial. This works but it's pretty undesirable to share a root folder.
Perhaps there's a better way of doing the access that will sidestep the need for having and querying SMB shares...?
Found the answer elsewhere on stackexchange answered by mivk.
Run the following command and capture the output.
sharing -l
This gives a slightly verbose list of file shares with separate details for afp and smb which can be parsed to get a list of shared folders on the local machine. Tested on Catalina. It's possible that this command will fail to run if file sharing is not enabled in System Preferences.
Situation: I'm on a stand-alone development computer running Windows 7. Not connected to any Windows Server. Would like to test a Window application's ability to use UNC paths. Will be transferred later to a Linux server (not at my location), hence the desire to use a cross-platform path mechanism (UNC) (//servername/sharename), rather than a Window's mapped drive (X:\foldername).
The application is Autodesk Maya 2014. A project's main file contains many references to other files. These file references can be relative paths ("subfolder/filename.ext"), absolute paths ("H:/projects/this_project/subfolder/filename.ext"), or UNC paths ("//servername/projects/.." or "servername/assets/..").
The app permits forward slashes, and maps those to the correct character on different OSes. Wherever possible, I use relative paths.
But I have a situation where a plug-in is not correctly working with relative paths, so I have resorted to using some absolute paths. It has been requested that I change these from the current mapped drive form, to UNC paths. REASON: the data will be transferred to a render farm, running Linux. A Linux version of the app will be used. (So my question isn't about accessing Linux files from my Windows box; it is about setting up all the data so that when everything is moved to the render farm, it will still run.)
Due to the combination of plug-ins and features we are using in Maya, I am not 100% certain I can convert all paths to relative form. (Questions there for Maya forums.) So as a fallback, I need to test with UNC paths. Am asking what it would take to set this up on my Windows 7 PC, without actually connecting to a server computer. (Don't have Linux nor Windows Server set-up at my location.)
I don't normally do network-related programming, nor server programming, so the various possible solutions are not familiar to me.
Googling suggests some basic techniques, that may or may not be relevant. Before I spend more time on this, want to know if I am going in the correct/easiest direction.
installing a local DNS server and editing its hosts file. Such as:
http://sourceforge.net/projects/acrylic/
http://sourceforge.net/projects/dhcp-dns-server/
.. but I don't have a domain name, I just have a (future) network computer name, so this is not relevant?
Editing LMHOSTS file
.. but this is just for mapping between a name and an IP address?
multiple NetBIOS names (OptionalNames)
Mentioned here:
http://www.mediamonkey.com/forum/viewtopic.php?t=51722&f=1
Which refers to:
https://serverfault.com/questions/23823/how-to-configure-windows-machine-to-allow-file-sharing-with-dns-alias
.. But that is talking about DNS, so is that relevant?
What I have succeeded in doing so far:
In Command Prompt (Run as Administrator):
net view \\localhost
or
net view \\mycomputernamehere
Lists shared folders on my PC. E.g. H:\temp Properties / Sharing, shared as "HTemp", which is listed.
So I think all I need to do is:
A. Share any folder with the desired name, e.g. "projects".
It will then be visible as "\\localhost\projects".
B. Convince Windows to use my local computer when I ask for "\\servername". I can then use "//servername/projects" in the app, which will ask Windows for "\\servername\projects", which then would be converted by Windows to "\\mycomputernamehere\projects".
... this (B) is the part I need help with. (3) above sounds like it is a solution. But to me it is rather arcane (editing the registry). Will it accomplish what I need? Is there an easy solution that doesn't involve registry editing?
And yes, somewhere along the way it dawned on me that the simplest solution is to rename my computer to "servername". I'll probably do that for this week.
But I'd still like to learn a way to alias my computer name, to fake a UNC path without actually renaming my computer. And without relying on a second computer acting as server.
This is a late answer, but for future reference:
Your suggestion of multiple NetBIOS names (OptionalNames) has worked for me to allow a Windows machine to accept UNC paths under other computer names.
For completess, you can combine this with adding the same alias's to the hosts file with the localhost ip 127.0.0.1 so IP traffic will always be redirected.
Maybe use the UNC version of localhost?
\\localhost\c$\tmp
Will map to your local c:\tmp folder.
I have tried all the suggestions from these posts:
Does anyone know where the Google App Engine local datastore file located for Mac OS X
Where is my local App Engine datastore?
Google App Engine local datastore path configuration
and I still can not find my local datastore.
I don't have the SDK set to clear the datastore on startup plus I can't find it even when the appserver is running. Does anyone know the file path for the Google App Engine's development server datastore file?
I am running GAE SDK 1.7.7.
Got this answer from a friend of mine. Worked for me and I hope it helps somebody else out.
By default, it's [local datastore] stored in a pretty much random directory. My current one looks like /private/var/folders/81/ABUNCHOFCRAP/T/..../datastore.db. Luckily, it's always called datastore.db. If yours is structured the same way mine is, you can find it using the following command in your Terminal:
find /private/var/folders -name datastore.db
That should print out the full path of the file you're looking for, along with a bunch of "Permission denied" messages. If that doesn't yield anything, use this command:
find / -name datastore.db
That one might take a while to run (it looks in all of the directories you have access to), but it'll definitely find it if it's there. Just copy one of those commands into your Terminal, and you should be all set. Let me know if this helps.
Disclaimers: This question is straddling a weird boundary between coding and SuperUser territory. I'm not even sure what terminology to use for half of what I'm asking so bear with me...
I'm working on a check in/out type of function for a remote client where they want to move some files back and forth between users' local machines and a central network location. They want the network location to be configurable. During the development for the past few weeks we've had the configured directory set to something simple like "C:\Storage" for initial testing purposes, and I created a Storage directory on the C: drive of my dev environment.
Today I got the network configuration they want to start using. I was hoping they'd use a mapped network drive so I could just map the same letter to my local drive and have my dev environment continue to work using their new configuration file. Unfortunately, the path they want to use points directly to some machine on their internal network using "\machinename\dir\dir\dir...".
Is there some way to set up my development environment such that when I encounter their network path using DirectoryInfo or whatever it will resolve to a local directory? If it was a mapped network drive I could use subst at the command prompt to point their letter at a directory on my local drive, but with this full path I don't know how to do something similar or if it's possible.
Now that I understand your problem a little better:
If you want to access your local computer using a UNC path, you'll need to setup a share, which it sounds like you already have. Then you can access it via:
\\localhost\c$\dir\dir
Hopefully that is good enough to get your work done on the dev side.
Is there any way, any chance at all to access entire filesystem in SL app with elevated trust?
That will work both in Windows and Mac?
Through AutomationFactory,PInvoke or unmanaged code?
I need an app that could read local drives, folders and files.
UDP: Ok, seems it's possible to read folders and files using classes of System.IO from mscorlib. Although you still can't get information about local mounted drives. There is no DriveInfo in Silverlight's mscorlib :(
Ok I have an idea about this.
It is straightforward enough with Windows, to get the list of the local drives you can use AutomationFactory. There is plenty amount of examples if you google it. Search for something called SilverlightFileExplorer.
Now on a Mac you can use Directory.EnumerateDirectories("/") and then it gets all the folders in the root. Including Volumes folder which contains shortcuts to the local drives. I'm not an expert of Berkeley System Distribution (BSD) Unix filesystems, so I can't really promise that it would work on any Mac, but this approach works on mine.
I'm still playing around with that. When I get working prototype I'll probably share it through github or something.