C# ASP.Net と Visual Studio 2012 Ultimate を使用。
フォームの一部のコードを再利用しました。ftp サーバーから画像をダウンロードします。
public class FTPdownloader
{
public Image Download(string fileName, string ftpServerIP, string ftpUserID, string ftpPassword)
{
FtpWebRequest reqFTP;
Image tmpImage = null;
try
{
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + "/" + fileName));
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
Stream ftpStream = response.GetResponseStream();
tmpImage = Image.FromStream(ftpStream);
ftpStream.Close();
//outputStream.Close();
response.Close();
}
catch (Exception ex)
{
//MessageBox.Show(ex.Message);
}
return tmpImage;
}
}
うまく機能し、フォームでこのように呼び出すだけです。
imgPart.Image = ftpclass.Download("" + "" + ".jpg", "address/images", "user", "pass");
今、これはwinformsに最適です。私の新しいプロジェクトは、asp.net Web フォームです。同じことをするためにそれが必要です。私はこのコードを再利用しましたが、問題ないようですが、メソッドを img.Image に呼び出すと、img.Image が asp.net に存在しないことがわかりました。基本的には画像を返しますが、私が見つけることができる最も近いものは、もちろん文字列である Img.ImageUrl です。
だから、これがこのコードへのわずかな変更であることを願っています。
どんな助けでも素晴らしいでしょう。みんなありがとう!