本番サーバーから ftp でファイルを作成する際に問題があります。次のコードは開発サーバーで正常に動作していますが、ホスティングを購入したサイトの運用サーバーにコードを移動するとエラーが発生します
コード
string fullname = Convert.ToString(TxtBx_FullName.Text);
if (FU_Img.HasFile)
{
string ftpUrl = "";
HttpPostedFile userPostFile = FU_Img.PostedFile;
string uploadUrl = @"ftp://abc/upload/u" + fullname;
string uploadFileName = Path.GetFileName(FU_Img.FileName);
uploadFileName = "image." + uploadFileName.Split('.')[1];
Stream streamObj = userPostFile.InputStream;
Byte[] buffer = new Byte[userPostFile.ContentLength];
streamObj.Read(buffer, 0, buffer.Length);
streamObj.Close();
streamObj = null;
// FtpWebResponse CreateForderResponse;
if (!GetAllFilesList(uploadUrl, "xyz", "******"))
{
FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(uploadUrl);
ftp.Method = WebRequestMethods.Ftp.MakeDirectory;
ftp.Credentials = new NetworkCredential("xyz", "******");
FtpWebResponse response = (FtpWebResponse)ftp.GetResponse();
}
//if (CreateForderResponse.StatusCode == FtpStatusCode.PathnameCreated)
ftpUrl = string.Format("{0}/{1}", uploadUrl, uploadFileName);
FtpWebRequest requestObj = FtpWebRequest.Create(ftpUrl) as FtpWebRequest;
requestObj.KeepAlive = false;
requestObj.UseBinary = true;
requestObj.Method = WebRequestMethods.Ftp.UploadFile;
requestObj.Credentials = new NetworkCredential("xxxx", "xxxxxx");
Stream requestStream = requestObj.GetRequestStream(); <----- error
requestStream.Write(buffer, 0, buffer.Length);
requestStream.Flush();
requestStream.Close();
requestObj = null;
エラー
スタックトレース
[WebException: The remote server returned an error: (550) File unavailable (e.g., file not found, no access).]
System.Net.FtpWebRequest.SyncRequestCallback(Object obj) +341
System.Net.FtpWebRequest.RequestCallback(Object obj) +23
System.Net.CommandStream.Dispose(Boolean disposing) +19
System.IO.Stream.Close() +20
System.IO.Stream.Dispose() +10
System.Net.ConnectionPool.Destroy(PooledStream pooledStream) +188
System.Net.ConnectionPool.PutConnection(PooledStream pooledStream, Object owningObject, Int32 creationTimeout, Boolean canReuse) +118
System.Net.FtpWebRequest.FinishRequestStage(RequestStage stage) +655
System.Net.FtpWebRequest.GetRequestStream() +795
MentorMentee.SignUp.signup.Btn_Preview_Click(Object sender, EventArgs e) +954
System.EventHandler.Invoke(Object sender, EventArgs e) +0
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9553178
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724
私が見つけたのは、属性 KeepAlive を false にすることでしたが、機能しませんでした。どこが間違っているのですか?