- Home /
How to write/read .txt on FTP (Javascript)
Hi I want to be able to Write and Read files from my ftp server.
I have my scripts set up to do what i want but only localy.
Here is what i use:
import System; import System.IO;
var PropertyNumber : String ="PropertyNumber"; var PropertyOwner : String = "Nobody";
function Update () { if(File.Exists("PlayerInfo/Property"+PropertyNumber+".txt")) {
var si = File.OpenText("PlayerInfo/Property"+PropertyNumber+".txt"); var line = si.ReadLine(); PropertyOwner=line; } }
This works but i cannot just write any url in the File.OpenText("") It only works localy for now.
I just need to know how to connect to my ftp server.
I also need to be able to write txt files on my server.
Any help welcome!
Answer by Kourosh · May 02, 2011 at 11:34 AM
I'm not if you can write on a txt file on your ftp server directly from your application. It requires you to login first. My suggestion is to write a php cgi and place it somewhere on your webserver and then using a form in unity submit your data to that php which will then write it to a text file for you.
Here is how to write the PHP
http://www.tizag.com/phpT/filewrite.php
Here is how to create the wwwform in unity. http://unity3d.com/support/documentation/ScriptReference/WWWForm.html
Thanks i hope ill get it after some reading, first attempts where unsuccesssfull.
Answer by Zhapness · May 03, 2011 at 12:16 PM
hmm.. have been trying to do this for 3 hours now, somebody should make a guide for this damn.
I assume you have problem writing the php. Here's another link for writing the php.http://www.codingforums.com/showthread.php?t=47311 I'm not sure how familiar you are with posting a html form to a server-side script. You can understand the concept here:http://www.tizag.com/phpT/forms.php What will change in your case is that ins$$anonymous$$d of making the html form you'll use unity to create the form for you and the post to the server-side script(the php I mean).
var URL= "http://www.$$anonymous$$YSIT$$anonymous$$com/gameData/cgi.php";
function OnDisconnectedFromServer(info : NetworkDisconnection) {
if(networkView.is$$anonymous$$ine) { var form = new WWWForm(); form.AddField("x position"transform.position);
var w = WWW(URL, form);
yield w;
if(w.error !=null)
{
print(w.error);
}
else
print("Finished uploading position");
Network.Destroy(gameObject);
}
}
It does nothing, i dont know any php at all, i will need a specific example to understand and use it.
Your answer
Follow this Question
Related Questions
I cant read the file i wrote, unless i reload it in VS. 1 Answer
Unity networking tutorial? 6 Answers
FTP Upload Files 2 Answers
Dat File Location 1 Answer