1、获取file文件流之后,直接保存
var file = Request.Files["upLoadExcel"];
file.SaveAs(Server.MapPath("/") + @"ContentUpload" + file.FileName);
2、转变为流,再上传至ftp,参考:http://blog.csdn.net/qucooln/article/details/6168352
try
{
var file = Request.Files["upLoadExcel"];
var fileName = GetFileName(file.FileName);
FtpWebRequest reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://192.168.1.21:21/" + fileName));
try
{
reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
reqFTP.Credentials = new NetworkCredential("sa", "sa");
Stream requestStream = reqFTP.GetRequestStream();
byte[] buffer = new byte[file.ContentLength];
file.InputStream.Read(buffer, 0, file.ContentLength);
requestStream.Write(buffer, 0, buffer.Length);
requestStream.Close();
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
response.Close();
}
catch (Exception ex)
{
reqFTP.Abort();
}
return Json(new { Success = true, FileUrl = "http://192.168.1.21:7878/" + fileName }, JsonRequestBehavior.AllowGet);
//file.SaveAs(Server.MapPath("/") + @"ContentUpload" + fileName);
//return Json(new { Success = true, FileUrl = "Content/Upload/" + fileName }, JsonRequestBehavior.AllowGet);
}
catch(Exception err)
{
return Json(new { Success = false, Msg = err.Message }, JsonRequestBehavior.AllowGet);
}