- Home /
How to Retrieve List of Files on FTP Server
I need to be able to obtain a list of files and/or the file hierarchy on my FTP server from any type of UNITY application (web, Desktop, iPad, etc.) so I can populate my file browser; once I have the addresses I know I can use the WWW class to download them (they will all be plain text files). Does anyone know how to do this?
Thanks!
Answer by Bunny83 · Mar 09, 2011 at 09:58 PM
You should be able to use System.net.sockets even in Webplayer but you need to offer a Socket policy. Unity just says that sockets are restricted in the webplayer and you can't open listen sockets but you should be able to connect to your ftp if you can provide this policy.
I've found this article and the Unity MonoCompatibility page says that FtpWebRequest stuff will work inside the Webplayer. I don't know how Unity will check the crossdomain restrictions when using that classes, but in general I think it should be possible.
Thank you for your suggestion. About FTPWebRequest - it works great on the Desktop and iPad, but it does not work for the Web Player; the error is: "error CS0117: System.Net.WebRequest$$anonymous$$ethods' does not contain a definition for
Ftp'"
Hmm, that's strange. It looks like Unity removed the definition for webbuilds. Depending on what FTP protocol version you use/want use you could handle the protocol yourself if you have the knowledge and time to create your own FTP client on top of sockets. But if your ftp-server have also a web-server I think it's much easier to create a php script that returns the directory listing as xml, csv, html, or what ever :D
Answer by cmkbim · Jan 02, 2015 at 05:06 PM
The error you are getting can be resolved with passing the actual string value for the method and in your example of the list you will use NLST. But once you do this you will start getting the crossdomain.xml stuff.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://xxx.com/www/");
request.Credentials = new NetworkCredential("user", "password");
request.Method = "NLST";