/// <summary> /// 从长途处事器下载文件到本地 /// </summary> /// <param>下载到本地后的文件路径,包罗文件的扩展名</param> /// <param>长途处事器路径(共享文件夹路径)</param> /// <param>长途处事器(共享文件夹)中的文件名称,包罗扩展名</param> public static void TransportRemoteToLocal(string src, string dst, string fileName) //src:下载到本地后的文件路径 dst:长途处事器路径 fileName:长途处事器dst路径下的文件名 { if (!Directory.Exists(dst)) { Directory.CreateDirectory(dst); } dst = dst + fileName; FileStream inFileStream = new FileStream(dst, FileMode.Open); //长途处事器文件 此处假定长途处事器共享文件夹下确实包罗本文件,,否则措施报错 FileStream outFileStream = new FileStream(src, 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(); }