[RESOLVED] FTP Upload Error
I can't get this ftp upload file function I got from msdn to work:
Code:
private static void uploadFile(string FTPAddress, string filePath, string username, string password)
{
//Create FTP request
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(FTPAddress + "/" + Path.GetFileName(filePath));
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential(username, password);
request.UsePassive = true;
request.UseBinary = false;
request.KeepAlive = false;
//Load the file
FileStream stream = File.OpenRead(filePath);
byte[] buffer = new byte[stream.Length];
stream.Read(buffer, 0, buffer.Length);
stream.Close();
//Upload file
Stream reqStream = request.GetRequestStream();
reqStream.Write(buffer, 0, buffer.Length);
reqStream.Close();
}
I get an error on this line:
Stream reqStream = request.GetRequestStream();
saying: Error 550, Permissions denied
Which is not a C# error, but an FTP error from my ftp server stating that I need more permissions, but I already have full and if I log onto the ftp in another client I can upload files to any directory.
Therefore something must be wrong with the code, anyone that got a clue?
Re: [RESOLVED] FTP Upload Error
Re: [RESOLVED] FTP Upload Error
Of course :)
Actually there was nothing wrong with the code, just the way I passed the parameters to the function :blush:
As I had tried writing my own upload function but not suceeded before, that lead to me passing the "string FTPAdress" wrong.
When I got the error I wrote about I passed it as such:
"ftp://mysite.com/myfiles/file.jpg"
But then I realised that the function already merged the filename with the path in the code, I didn't have to do it myself so the proper input was this:
"ftp://mysite.com/myfiles/"
So that was the error I got and the problem I made and now it works great :)