.NET Ftp查看图片


其实FTP查看图片很简单,首先我们要根据用户名,密码,还有服务器地址登录上ftp服务器。
然后把前端对应显示图片名称传到后台即可。我前端显示图片是采用的easyui弹框,其实只需一个image标签即可。
如下代码:
<div id="dlg">
    <img src="" id="simg" />
</div>
 
//js代码
function OclickAttachmentFile() { $('#dlg').dialog({ title: '签证预览', width: 800, height:650, resizable:true, closed: false, cache: false, modal: true }); var img = new Image(); $(img).bind("load", function () { $("#simg").attr("src", this.src); }); img.src = "/Common/file/GetFileUpload?fillName=" + '@Model.ErpPoMasterExtModel.DeliveryVoucherOriginName'; }
     //<summary>
        //获取文件
        //</summary>
        //<param name="fillName">图片名称</param>
        //<returns>图片流</returns>
        public FileResult GetFileUpload(string fillName)
        {
            string usercConfig = ScmConfig.CusReceiptFtpUser; //服务器用户名
            string pwdcConfig = ScmConfig.CusReceiptFtpPwd; //服务器密码
            string ftpSrccConfig = ScmConfig.CustomerReceiptFtp; //服务器地址
            FtpFileBase ftpFileBase = new FtpFileBase(usercConfig, pwdcConfig);

            FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpSrccConfig + fillName);
            request.Method = WebRequestMethods.Ftp.DownloadFile;

            request.Credentials = new NetworkCredential(usercConfig, pwdcConfig);

            FtpWebResponse response = (FtpWebResponse)request.GetResponse();

            Stream responseStream = response.GetResponseStream();

            return File(responseStream, "image/jpeg");

        }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM