Use Net Use to read and write files on other servers in the LAN in C #.

Source: Internet
Author: User

There are many solutions to perform file read/write operations on the LAN like processing files on the local disk,

FTP: the configuration is cumbersome and asynchronous transmission, resulting in complicated response to the results of the transfer;

Physical ing: You need to add a shared user account locally.

Net Use: You can directly Use the specified shared directory account (you do not need to create an account locally) to access the service. After using this doscommand to establish a connection, you can directly perform operations like local disk files.

 

The following is the implemented C # code
 

Code /// <Summary>
/// Connet to remote share folder
/// </Summary>
/// <Param name = "remoteHost"> remote server IP or machinename. domain name </param>
/// <Param name = "shareName"> share name </param>
/// <Param name = "userName"> user name of remote share access account </param>
/// <Param name = "passWord"> password of remote share access account </param>
/// <Returns> connect result </returns>
Public static bool Connect (string remoteHost, string shareName, string userName, string passWord)
{
Bool Flag = false;
Process proc = new Process ();
Try
{
Proc. StartInfo. FileName = "cmd.exe ";
Proc. StartInfo. UseShellExecute = false;
Proc. StartInfo. RedirectStandardInput = true;
Proc. StartInfo. RedirectStandardOutput = true;
Proc. StartInfo. RedirectStandardError = true;
Proc. StartInfo. CreateNoWindow = true;
Proc. Start ();
String dosLine = @ "net use \"
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.