none
How to read Remote file where user/passowrd is required RRS feed

  • Question

  • I am trying to do :

    Directory.GetFiles(input_folder, "*.log");

    where

    input_folder="\\192.168.1.2\c$\folder1"

    the server are not part of a domain.

    I get the error :

    {"The user name or password is incorrect.\r\n"}
    is there a method to read files using user/pass?


    • Edited by want 2 Learn Thursday, December 5, 2019 4:57 PM fixed code
    Thursday, December 5, 2019 4:55 PM

All replies

  • You can see this thread : Access to remote folder

    or use WNetAddConnection2 (P/Invoke)

    Thursday, December 5, 2019 5:31 PM
  • This same exact question was asked by somebody else in the forums just yesterday. As was stated there, UNC paths work just fine in .NET. However there are no options in .NET to pass alternate credentials when making IO calls therefore the current user's credentials are used.

    You're example is using the admin share which means the user running the app must have admin privileges on the remote server. You either need to adjust the permissions or create a share that can be read by a normal user.

    If that isn't an option then your only other choice is to map the drive. .NET doesn't provide any APIs for mapping drives so you have to P/Invoke the calls.


    Michael Taylor http://www.michaeltaylorp3.net

    Thursday, December 5, 2019 6:50 PM
    Moderator