zoukankan      html  css  js  c++  java
  • FileUpload上传至FTP

    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);
                }

  • 相关阅读:
    【LSA推荐算法】简单理解
    【数据分析案例】用户消费行为
    【Django】rest_framework 序列化自定义替换返回值
    【Django+Element UI】使用一个接口文件,搞定分页获取数据,模糊查询后分页获取数据
    【Django后端分离】使用element-ui文件上传
    JavaScript数组去重方法总结
    MySQL索引优化--对前缀索引使用like模糊匹配时的实际索引选择
    Linux命令--top
    Linux命令--free
    MySQL中的表的列设置为varchar(0)或char(0)
  • 原文地址:https://www.cnblogs.com/honzhez/p/3217062.html
Copyright © 2011-2022 走看看