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.
This is my error msg:
SocketException: No connection could be made because the target machine actively refused it.
System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP, Boolean requireSocketPolicy) System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) System.Net.FtpWebRequest.OpenControlConnection () Rethrow as WebException: Unable to connect to remote server System.Net.FtpWebRequest.OpenControlConnection () System.Net.FtpWebRequest.Process$$anonymous$$ethod () System.Net.FtpWebRequest.ProcessRequest ()
Answer by Kastenessen · Jun 23, 2016 at 02:20 AM
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.
http://answers.unity3d.com/questions/1206839/syntax-501-error-how-to-upload-without-error-to-ft.html
All done, it now uploads to my ftp server not a problem.
Your answer
Follow this Question
Related Questions
WebGL Build WWW class : Unknown Error 1 Answer
How to Upload File on Blob Storage using Sas URI ? 0 Answers
Unity, WebClient, Upload, Async and Threads. 0 Answers
Upload image from IOS gallery show no search result but works find in Android 0 Answers
PlayerInitEngineGraphics: GPU not supported; OpenGL 2.0 is required. (After cuda installation) 0 Answers