I am using c# in .NEt 2.0 to simply try to upload a file. Everything seems ok in the code, but it keeps failing at when I go to create a stream from the FtpWebRequest.GetRequestStream method.
Here is the code...
FtpWebRequest ftpRequest;
FtpWebResponse ftpResponse;
try
{
string fileName = Path.GetFileName(strCompleteFilePath);
ftpRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://myhost/" + fileName));
ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;
ftpRequest.Proxy = null;
ftpRequest.UseBinary = true;
ftpRequest.Credentials = new NetworkCredential("myUserID", "myPW");
ftpRequest.KeepAlive = false;
FileInfo ff = new FileInfo(strCompleteFilePath);
byte[] fileContents = new byte[ff.Length];
using (FileStream fr = ff.OpenRead())
{
fr.Read(fileContents, 0, Convert.ToInt32(ff.Length));
}
using (Stream writer = ftpRequest.GetRequestStream())
{
writer.Write(fileContents, 0, fileContents.Length);
}
ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
}
And the error....
{System.Net.WebException: The remote server returned an error: (501) Syntax error in parameters or arguments.
at System.Net.FtpWebRequest.SyncRequestCallback(Object obj)
at System.Net.FtpWebRequest.RequestCallback(Object obj)
at System.Net.CommandStream.InvokeRequestCallback(Object obj)
at System.Net.CommandStream.Abort(Exception e)
at System.Net.FtpWebRequest.FinishRequestStage(RequestStage stage)
at System.Net.FtpWebRequest.GetRequestStream()