私はFtpWebRequest
現在ディレクトリを作成するために使用していますが、このような例外が発生しftp error 550: File unavailable
ます。ディレクトリを正常に作成できる場合もありますが、常にこの例外が発生します。
以下は私の CheckDir 関数です:
protected string CheckDir(string fullpath, string ip, string acc, string pwd)
{
string[] path = fullpath.Split(slash[1]);
bool result = false;
FtpWebRequest request = (FtpWebRequest)(WebRequest.Create(ip + path[2]));
request.Credentials = new NetworkCredential(acc, pwd);
request.Method = WebRequestMethods.Ftp.GetDateTimestamp;
request.Timeout = 10000;
try
{
using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
{
result = true;
}
}
catch (WebException ex)
{
FtpWebResponse response = (FtpWebResponse)ex.Response;
if (response != null && response.StatusCode == FtpStatusCode.ActionNotTakenFileUnavailable)
{
request = (FtpWebRequest)WebRequest.Create(ip + path[2]);
request.Credentials = new NetworkCredential(acc, pwd);
request.Method = WebRequestMethods.Ftp.MakeDirectory;
request.UsePassive = true;
request.UseBinary = true;
request.KeepAlive = false;
request.GetResponse();
result = true;
}
else
{
result = false;
}
}
if (result == true)
return path[2];
else
return null;
}