跨服务器保存文件:代码实现业务是将一个服务器上的文件保存到另一台服务器的共享目录下:
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Windows.Forms; 9 using System.IO; 10 11 namespace 网络共享做本地映射 12 { 13 public partial class Form1 : Form 14 { 15 public Form1() 16 { 17 InitializeComponent(); 18 } 19 20 21 string RemoteDirTo = @"\\Netnetnet-pc\站点发布"; //共享目录 22 string FilePathTo = @"\Test\";//共享目录(子目录) 23 string RemoteDirToUser = "admin2";//共享目录服务器用户 24 string RemoteDirToPwd = "123";//共享目录服务器密码 25 string RemoteDirFromFile = @"d:\aaaa.txt";//本地文件 26 string RemoteDirFromUser = "administrator";//本地用户 27 string RemoteDirFromPwd = "zmkm";//本地密码 28 29 private void button3_Click(object sender, EventArgs e) 30 { 31 try 32 { 33 DataExtractor.SaveFileToService(RemoteDirTo, FilePathTo, RemoteDirToUser, RemoteDirToPwd, RemoteDirFromFile, RemoteDirFromUser, RemoteDirFromPwd); 34 } 35 catch (Exception ex) 36 { 37 MessageBox.Show(ex.Message); 38 } 39 } 40 41 42 } 43 }