How to pass username and password to network location
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Marcin Kowalski
el 20 de Jun. de 2024
Hi all,
I am trying to programatically access the network share under MATLAB dir command. It is working perfectly till the network is not password protected.
I am trying to pass the credentials as follows
dir('\\server\share /user:test testpassword')
but it gives me the "not found. Check the path or file permissions." error. I appreciate any hints.
0 comentarios
Respuesta aceptada
dpb
el 20 de Jun. de 2024
<dir> doesn't know anything about user; there is no switch processing so it thinks you're looking for a file named
\\server\share /user:test testpassword
as the file.
Try just
dir('\\server\share')
or
dir('\\server\share\*.*')
For a test,
>> dir('\\mfs0.sccc.edu\DevelopAlumni')
. ERF-Employee-Requisition-Form.doc STUB.LOG
.
.
.
works here when connected via VPN to the college...although I do have the drives mapped so that
dir('H:')
will produce the same result. The login credentials are handled by the VPN interface and the (Windows OS)
net use H: \\networksharename USERPASSWORD /USER:username /PERSISTENT:YES
I suspect you'll have to do something similar first to establish the link.
2 comentarios
dpb
el 21 de Jun. de 2024
Editada: dpb
el 21 de Jun. de 2024
Clearly it is not mapped permanently as you think...and I have no idea what you're thinking about in the "Matlab 'dir' takes the default Windows credentials to log in to a drive.". dir simply passes the file name to the OS and doesn't have concept of logging in specifically for the given time; the network drive is either already mapped/accessible to the session or it isn't.
What does
!net use
from the command line return? It is not going to show your network drive, I'm sure.
Have you executed the net use
net use H: \\networksharename USERPASSWORD /USER:username /PERSISTENT:YES
from a command session and verified after that the drive is mapped? That is what I do routinely when logging in and connecting to the remote machine through the VPN. For convenience, I've put the commands for all the drives I map (various locations on the same physical drive) in batch files so don't have to type out the whole thing every time, but this has to be done (but only once) every session.(*)
If that doesn't solve your problem, you'll have to talk to your local IT people about specifics for your system...
(*) That's user session, not per MATLAB instance or any other application; if the system has the drive mapped, it's global.
Más respuestas (0)
Ver también
Categorías
Más información sobre File Operations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!