How to pass username and password to network location

10 Ansichten (letzte 30 Tage)
Marcin Kowalski
Marcin Kowalski am 20 Jun. 2024
Bearbeitet: dpb am 21 Jun. 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.

Akzeptierte Antwort

dpb
dpb am 20 Jun. 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 Kommentare
Marcin Kowalski
Marcin Kowalski am 21 Jun. 2024
Thank you for the answer. To clarify. First I log in into this drive natively from Windows Explorer, giving credentials, with save option active. However, for some reason any other application still needs the login and password. It is the same with Matlab. Normally, Matlab 'dir' takes the default Windows credentials to log in to a drive. In this case, for some reason, I need to provide the login and pass everytime i want to access the storage.
Morever, this storage is mapped under Windows, so it should work easily.
This is why I ask for the solution.
dpb
dpb am 21 Jun. 2024
Bearbeitet: dpb am 21 Jun. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu File Operations finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by