I try upload file to ftp. The file is sent to the server correctly, but try-catch catches the web exception with status 150. Where is the problem?
try
{
var request = (FtpWebRequest)WebRequest.Create(host);
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential(user, password);
request.EnableSsl = true;
byte[] data;
using (var sourceStream = new StreamReader(filePath)
{
data = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
}
request.ContentLength = data.Length;
using (var requestStream = request.GetRequestStream())
{
requestStream.Write(data, 0, data.Length);
}
using (var response = (FtpWebResponse)request.GetResponse())
{
Console.WriteLine($"Upload File Complete,status{response.StatusDescription}");
}
}
catch(WebException ex)
{
var response = (FtpWebResponse)ex.Response;
}