I use FtpWebRequest to upload a file to FTP, if I set the method to WebRequestMethods.Ftp.UploadFileWithUniqueName, following exception will be catched in line
Stream requestStream = request.GetRequestStream();
System.Net.WebException: 'The remote server returned an error: (550) File unavailable (e.g., file not found, no access).'
This is my source code. And the .NET Framework is .NET Framework 4
FtpWebRequest request;
string absoluteFileName = Path.GetFileName(fileName);
request = WebRequest.Create(new Uri(string.Format(@"ftp://{0}/{1}", fullAddr, absoluteFileName))) as FtpWebRequest;
request.Method = WebRequestMethods.Ftp.UploadFileWithUniqueName;
request.UseBinary = true;
request.KeepAlive = false;
request.UsePassive = false;
request.Credentials = new NetworkCredential(user, pass);
request.Proxy = null;
using (FileStream fs = File.OpenRead(fileName))
{
request.ContentLength = fs.Length;
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
fs.Close();
fs.Dispose();
Stream requestStream = request.GetRequestStream();
requestStream.Write(buffer, 0, buffer.Length);
requestStream.Flush();
requestStream.Close();
}