FTP Uploading from Pc or Device, permissions, rejected by remote machine.

Hello,

For a client I require to be able to upload via ftp or url somehow to a server.

I have setup the server with an ftp server and have a heap of code I’ve been trying to work on to get it to upload a file successfully, either from my pc or from a device.

I save the file first with binary serializer:

  try
       {

          Stream stream = File.Create(Application.dataPath + @"/" +  nameOfFile + ".txt");
          BinaryFormatter bformatter = new BinaryFormatter();
          bformatter.Serialize(stream, resultsInfo);
          stream.Close();
                
      }
          catch (UnauthorizedAccessException)
       {
                    print("SAVING ERROR!!!");            
       } 

Which is nice and simple and cut down and works. Then I use this to try and upload it to my ftp client:

      ftpRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftp + nameOfFile + ".txt"));
      ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;
      ftpRequest.UsePassive = true;
      ftpRequest.UseBinary = true;
      ftpRequest.Credentials = new NetworkCredential(creds0, creds1);


      FileInfo finfo = new FileInfo(Application.dataPath + @"/" + nameOfFile + ".txt");
      byte[] fileContents = new byte[finfo.Length];

                
                using (FileStream stream = finfo.OpenRead())
                {
                    stream.Read(fileContents, 0, Convert.ToInt32(ff.Length));
                   // done = true;
                }

                using (Stream writer = ftpRequest.GetRequestStream())
                {
                    writer.Write(fileContents, 0, fileContents.Length);
                }

Which is some code I have borrowed from unity answers somewhere to try to help me understand how this works and get it to work lol. (if you cant make it fake it lol).

It gives me an error and freezes up. The error is that its rejected by the other machine.

I feel I am close to getting this. Would it be permissions somehow? Is there something I have to do with my remote server?

Would like to find a solution, I’ve been working long hrs to try to work this out as networking is a big subject and I am only just getting into it now.

Please help. Cause I am not sure what I am doing when it comes to networking and ftp’s and the such.

Okay, so the permission’s rejected thing is to do with the remote server not having an accessible user account setup in the ftp server.

So once my friend help me with understanding how to do that, I was able to get past that error by setting up my remote server users and allowing access rights (read and write and create dir and all).

And was then later able to solve the syntax error I had and that’s in another question if anyone wants to look.

All done, it now uploads to my ftp server not a problem.