码迷,mamicode.com
首页 > Windows程序 > 详细

C# FTP下载图片转为Base64

时间:2019-02-21 00:34:07      阅读:346      评论:0      收藏:0      [点我收藏+]

标签:live   bre   read   图片   red   use   orm   bit   try   

public string GetFtpBase64String(string FtpFilePath)
{
try
{
string sBase64String = string.Empty;
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(new Uri(FtpFilePath));
request.Method = WebRequestMethods.Ftp.DownloadFile;
request.UseBinary = true;
request.Credentials = new NetworkCredential(sFtpUserName, sFtpPassword);
request.UsePassive = false;
request.KeepAlive = false;
using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
{
using (Stream ftpStream = response.GetResponseStream())
{
using (Bitmap bmp = new Bitmap(ftpStream))
{
using (MemoryStream ms = new MemoryStream())
{
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] arr = new byte[ms.Length];
ms.Position = 0;
ms.Read(arr, 0, (int)ms.Length);
sBase64String = Convert.ToBase64String(arr);
}
}
}
}
return sBase64String;
}
catch (Exception ex)
{
return "";
}
}

C# FTP下载图片转为Base64

标签:live   bre   read   图片   red   use   orm   bit   try   

原文地址:https://www.cnblogs.com/Elcser/p/10409875.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!