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();
                                        
                    }

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!