Quantcast
Channel: Questions in topic: "webrequest"
Viewing all articles
Browse latest Browse all 387

Get echo output from PHP script which is on an FTP server with C#

$
0
0
Yeah I know, quite the title. Allow me to explain, For my school exams I am tasked with making a game which has to be playable in a browser, to do this, I'm using unity's webplayer. The game needs to keep track of highscores and such so I made a MySQL database which holds the scores. To connect to the database and read out the scores and other such data, I have written a PHP script. The PHP script is on an FTP server. The PHP script echo's the data it reads form the database, so if you'd run it in your browser, u'd get some text back like: "username;score". Now here comes the problem, I used to use a C# script to read the output form the PHP file(the username + score). I did this using unity's WWW class, however, sicne the PHP file has recently been placed onto the FTP server, a WWW request wont work anymore. I've managed to get as far as connecting to the FTP server and reading the actual PHP file (the actual PHP code), but that's of course useless to me! I need the html output it would give. Here's the code for all my scripts: The PHP code: The C# code: void ftp() { string serverPath = "ftp://ndc38.colo.bit.nl/map/ReadCities.php"; FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverPath); request.KeepAlive = true; request.UsePassive = true; request.UseBinary = true; request.Method = WebRequestMethods.Ftp.DownloadFile; request.Credentials = new NetworkCredential("helidrop", "5c1tLuae"); // Read the file from the server & write to destination using (FtpWebResponse response = (FtpWebResponse)request.GetResponse()) using (Stream responseStream = response.GetResponseStream()) using (StreamReader reader = new StreamReader(responseStream)) using (StreamWriter destination = new StreamWriter("hoi.txt")) { destination.Write(reader.ReadToEnd()); destination.Flush(); } } If any one has any advice on what to do, either how to get the echo form the PHP file or an alternative maybe? (as long as it doesn't take to much time to implement). I'd be incredibly grateful :) PS: I hope the post is kinda clear :P

Viewing all articles
Browse latest Browse all 387

Trending Articles