/// <summary> /// 文件上传 /// </summary> /// <param name="localFilePath">本地文件路径</param> public void Upload(string localFilePath) { FileInfo fileInf = new FileInfo(localFilePath); request = PrivateAction.OpenRequest(this.ftpUserID, this.ftpPassword, this.request, newUri(ftpURI + fileInf.Name), WebRequestMethods.Ftp.UploadFile); request.ContentLength = fileInf.Length; int buffLength = 2048; byte[] buff = new byte[buffLength]; int contentLen; using (var fs = fileInf.OpenRead()) { using (var strm = request.GetRequestStream()) { contentLen = fs.Read(buff, 0, buffLength); while (contentLen != 0) { strm.Write(buff, 0, contentLen); contentLen = fs.Read(buff, 0, buffLength); } } } }
/// <summary> /// 更改目录或文件名 /// </summary> /// <param name="currentName">当前名称</param> /// <param name="newName">修改后新名称</param> public void ReName(string currentName, string newName) { request = PrivateAction.OpenRequest(this.ftpUserID, this.ftpPassword, this.request, newUri(ftpURI + currentName), WebRequestMethods.Ftp.Rename); request.RenameTo = newName; response = (FtpWebResponse)request.GetResponse(); }