.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