下载分享文件威尼斯网站

2019-09-21 01:59栏目:威尼斯网站

执行

        public static void Run()        {            var state = ConnectState(@"\192.168.10.160excel", "fish", "12345");            if             {                //    共享文件夹的目录                  TransportRemoteToLocal(@"\192.168.10.160excel1ff79391090d4e8fa507ada85bae31ec.xlsx", @"D:Fish-a1.xlsx");            }        }

链接

/// <summary>          /// 连接远程共享文件夹          /// </summary>          /// <param name="path">远程共享文件夹的路径</param>          /// <param name="userName">用户名</param>          /// <param name="passWord">密码</param>          /// <returns></returns>          public static bool ConnectState(string path, 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 "   path   " "   passWord   " /user:"   userName;                proc.StandardInput.WriteLine;                proc.StandardInput.WriteLine("exit");                while (!proc.HasExited)                {                    proc.WaitForExit(1000);                }                string errormsg = proc.StandardError.ReadToEnd();                proc.StandardError.Close();                if (string.IsNullOrEmpty)                {                    Flag = true;                }                else                {                    throw new Exception;                }            }            catch (Exception ex)            {                throw ex;            }            finally            {                proc.Close();                proc.Dispose();            }            return Flag;        }

下载

/// <summary>          /// 从远程服务器下载文件到本地          /// </summary>          /// <param name="saveSrc">保存到本地的路径:下载到本地后的文件路径,包含文件的扩展名</param>          /// <param name="sourceSrc">远程服务器路径  远程服务器中的文件名称,包含扩展名</param>          public static void TransportRemoteToLocal(string sourceSrc, string saveSrc)        {            //  远程服务器文件  此处假定远程服务器共享文件夹下确实包含本文件,否则程序报错             if (!File.Exists(sourceSrc))                return;             FileStream inFileStream = File.OpenRead(sourceSrc);            //  从远程服务器下载到本地的文件              FileStream outFileStream = new FileStream(saveSrc, FileMode.OpenOrCreate);            byte[] buf = new byte[inFileStream.Length];            int byteCount;            while ((byteCount = inFileStream.Read(buf, 0, buf.Length)) > 0)            {                outFileStream.Write(buf, 0, byteCount);            }            inFileStream.Flush();            inFileStream.Close();            outFileStream.Flush();            outFileStream.Close();        }

版权声明:本文由威尼斯网站发布于威尼斯网站,转载请注明出处:下载分享文件威尼斯网站