アップロード中の接続不良による FTP 550 エラー「アクセスが拒否されました」の解決方法。問題なくアップロードできる場合があるため、サーバーが既に許可を与えていると確信しています。サーバーの接続が遅かったためにこれが発生したという投稿を読みましたが、誰かがこの問題を解決できるかどうか知りたいです
ここに私のコードがあります:
public bool FTPUploadFunct(string uploadto2, string newskinlocation2)
{
bool FTPUploadFunct = true;
MethodInvoker methodInvokerDelegate = delegate()
{ toolStripStatusLabel1.Text = "Uploading...."; };
this.Invoke(methodInvokerDelegate);
try
{
//delete old file
FtpWebRequest requestFileDelete = (FtpWebRequest)WebRequest.Create(uploadto2);
requestFileDelete.Credentials = new NetworkCredential("FTPUser20", "1234");
requestFileDelete.Method = WebRequestMethods.Ftp.DeleteFile;
FtpWebResponse responseFileDelete = (FtpWebResponse)requestFileDelete.GetResponse();
//upload new file
FtpWebRequest requestFTPUploader = (FtpWebRequest)WebRequest.Create(uploadto2);
requestFTPUploader.Credentials = new NetworkCredential("FTPUser20", "1234");
requestFTPUploader.Method = WebRequestMethods.Ftp.UploadFile;
FileInfo fileInfo = new FileInfo(newskinlocation2);
FileStream fileStream = fileInfo.OpenRead();
int bufferLength = 2048;
byte[] buffer = new byte[bufferLength];
Stream uploadStream = requestFTPUploader.GetRequestStream();
int contentLength = fileStream.Read(buffer, 0, bufferLength);
while (contentLength != 0)
{
backgroundWorker1.ReportProgress((int)(contentLength / fileInfo.Length));
uploadStream.Write(buffer, 0, contentLength);
contentLength = fileStream.Read(buffer, 0, bufferLength);
}
uploadStream.Close();
fileStream.Close();
backgroundWorker1.ReportProgress(100);
requestFTPUploader = null;
}
catch (WebException ex)
{
FTPUploadFunct = false;
String status = ((FtpWebResponse)ex.Response).StatusDescription;
MessageBox.Show(status + "error while in FTPUploadFunc");
errorNumber = (int)((FtpWebResponse)ex.Response).StatusCode;
if (errorNumber == 550)
{
MessageBox.Show("550" + "error while in FTPUploadFunc2");
};
}
return FTPUploadFunct;
}
何度も立ち往生
requestFileDelete.Method = WebRequestMethods.Ftp.DeleteFile;
しかしいつか
requestFTPUploader.Method = WebRequestMethods.Ftp.UploadFile;