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
userName = 'user'
password = 'pw'
i = 0
directory = '\folder'
# Parent directory path
parent_dir = '//servername'
map_dir = "C:/Windows/System32/net.exe use Z: " + parent_dir + " /persistent:no"
#Target directory to copy files to
trg = 'z:'+ directory
isdir = os.path.isdir(trg)
print ('Directory Exists')
# Create the directory
print("Directory '%s' created" %directory)
#except OSError as error:
print('Error making directory')
I get this in the script console
C:/Windows/System32/net.exe use Z: //AZUTBLPD01/Tableau_Data/NewPragueEngineering/FXE_Tenders /persistent:yes
Error making directory
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.
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).
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.
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.
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.)