C# FTP下载图片转为Base64
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 "";
}
}