File Transfer From Local system to Remote Server RRS feed

  • Question

  • Currently i am rewriting the very old VB application to C#.net. My Requirement is to transfer a file from local system to remote server. I have to connect to the remote server share path using domain name, server name, user id, password. After accessing the share path i have to transfer the file. 

    File.copy option doesnt work for remote server, if am not wrong.

    Is there any existing library in C#.net  to connect to remote server and transfer file.

    Please help me on this.

    Friday, May 8, 2015 11:27 AM


  • In order to connect to a remote server using credentials other than the current user's credentials you'll need to call down to Win32 to set up a mapped drive via WNetAddConnection2 or similar.  UNC paths can be used in file calls but they will use the current user's credentials.  Another alternative would be to use WMI which will allow you to specify credentials when you connect to the remote server.  However I do not know how fast such a request would be.  Yet another alternative, if the account you'll be using can log onto the local machine, is to impersonate the remote user account (again, must be able to log on to the local machine using that account) and then you can use the standard file APIs.

    This question has come up recently in the forums.  Please search for the solutions that have already been posted to get code samples for how to do some of this.

    Michael Taylor

    • Proposed as answer by Kristin Xie Monday, May 11, 2015 2:48 AM
    • Marked as answer by Kristin Xie Tuesday, May 19, 2015 1:42 AM
    Friday, May 8, 2015 2:50 PM