How to pass username and password to network location
조회 수: 5 (최근 30일)
이전 댓글 표시
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
채택된 답변
dpb
2024년 6월 20일
<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
dpb
2024년 6월 21일
편집: dpb
2024년 6월 21일
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!