Map Network Drive on Clients PC

I need to give ignition access to a folder on the server. The vision client could be accessed from a number of PCs and the access currently relies on the user's credentials. I've tried the following script but it doesn't appear to map a drive

import os.path
import shutil
import glob
import csv

userName = 'user'
password = 'pw'
startTime= (system.date.now())
i = 0
# Directory
directory = '\folder'
  
# Parent directory path
parent_dir = '//servername'
map_dir = "C:/Windows/System32/net.exe use Z: " + parent_dir + " /persistent:no"
print map_dir
os.system(map_dir)

#Target directory to copy files to
trg = 'z:'+ directory
print (trg)
isdir = os.path.isdir(trg)
if (isdir):
	print ('Directory Exists')
else:
	try:  
		# Create the directory
		os.mkdir(trg)
		print("Directory '%s' created" %directory)
		
	#except OSError as error:
	except:
		#print(error)
		print('Error making directory')
		quit()

I get this in the script console
C:/Windows/System32/net.exe use Z: //AZUTBLPD01/Tableau_Data/NewPragueEngineering/FXE_Tenders /persistent:yes
1
z:\FXE0014
Error making directory

I found the instructions for mapping a drive but wouldn't this do it on the host?
Mapping a Network Drive - Ignition User Manual 8.1 - Ignition Documentation (inductiveautomation.com)

I would not try to map the shared drive. Since client applications are already running "as" the user who has access, just read the file/directory using the fully-qualified path, something like \\server\path\to\drive. Then you don't need to mess around with mounting at all.

3 Likes

This way would also prompt the user for the specific credentials as well if required I believe.

Trying to do it in a script, unless you accept input for a username/password, would require you to hardcode the credentials and every client would be logging on as the same person - probably not what you want (and may cause issues).

Thanks. If the user doesn't have access to that path though, then the script fails. This is why i'm trying to map it.

I should add that we are trying to copy files to the server.

Is it important that the client see the folder or just that the gateway makes a folder?

You can map the drive on the gateway level with that link you sent. Then you can have a client send a message to the gateway to make the folder, so this folder can be made whether or not the client user currently has that drive mapped.

The files we need to copy reside on the client.

Are they anticipated to be large files? If they're on the smaller side, I think you can just do something with system.file.readFileAsBytes ont the client side to get the raw data of the file, send that along with a desired path in a payload of a message handler to the gateway, then on the gateway message handler, do a system.file.writeFile with those bytes after you figure out where it is you need to put the file.

I don't see why this wouldn't work for a larger file too but you would probably need to put it inside an invokeAsynchronous eventually or your client I think will freeze until the full file is sent over.

3 Likes

Use messages like Brian suggests. Then your message handler can enforce file destinations/naming conventions/et cetera. You can pass rather large files this way, 2MB for sure. If necessary, a background task sending chunks to the server is also doable.

Messaging is also cross-platform, so it would work the same with Linux clients and/or gateways. (Many will migrate to Linux for all of its security and reliability advantages at some point, I expect. In a hurry, possibly, if the environment encounters certain kinds of crises.)

3 Likes

Thanks guys. The guys can get up to 6 MB. I'll give this a try.