Syntax 501 error, How to upload without error to FTP Server
Hello,
I have a problem, its to do with improper syntax, am looking online everythere for a solution, maybe some knows what's wrong here. My server works and I can upload otherways to guest user.
Just in the app, it gives me a 501 syntax error. Here is the code, I know something isn't right, I think its to do with the file upload format or something, not sure. Please help?
ftpRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftp) );
ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;
ftpRequest.UsePassive = true;
ftpRequest.UseBinary = true;
ftpRequest.Credentials = new NetworkCredential("guest", "guest");
FileInfo finfo = new FileInfo(filePath);
byte[] fileContents = new byte[finfo.Length];
using (FileStream fread = finfo.OpenRead())
{
fread.Read(fileContents, 0, Convert.ToInt32(finfo.Length));
fread.Close();
}
using (Stream writer = ftpRequest.GetRequestStream())
{
writer.Write(fileContents, 0, fileContents.Length);
writer.Close();
}
Answer by Kastenessen · Jun 23, 2016 at 02:15 AM
I got it woking:
In ftp string I left out a "/" after the host address.
Also I had to add the filename to the FtpWebRequest.Create(ftp + filename + ".txt" - like that.
So it uploaded to my ftp server perfectly after these amendments.
Another small step for me in learning about networking.
Thanks anyway!
Your answer
![](https://koobas.hobune.stream/wayback/20220612083503im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to display .tif images via script? 1 Answer
What am i doing wrong here? (file.exists) 2 Answers
Unity, WebClient, Upload, Async and Threads. 0 Answers
Upload to any online webplayer platform 0 Answers