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

  • 相关阅读:
    CentOS Python 安装MySQL-python
    Ubuntu64位安装Adobe Reader 9.5.5
    Codeforces Round #316 (Div. 2) (ABC题)
    cocos2dx 3.2+ 项目创建与问题总汇
    Mongodb的索引
    uva 12083 Guardian of Decency (二分图匹配)
    Linux查看内存使用量和交换区使用量
    053第423题
    [Python]xlrd 读取excel 日期类型2种方式
    求解组合问题的一个迭代算法
  • 原文地址:https://www.cnblogs.com/honzhez/p/3217062.html
Copyright © 2011-2022 走看看