- Home /
Download files via FTP on Android with WWW class
I need to make a connection with a local FTP protocol between a computer (server) and my Android device (client). This should download files (images, OBJ,...) to be used in the Android app scene. I've used WWW class to create this connection and it works fine in the Unity player run in another computer as client. Once I've exported the same scene as Android apk it didn't work (I'm sure that FTP connection is stable and it works because I'm able to access to the files from the browser). Does anybody know if there is another way or there are problems in my code to use the FTP protocol on Android Unity app? (the client doesn't need any authorisation and the authentication is anonymous) Here is the code I use to download one image inside the scene and render it as a sprite.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Net;
using System.IO;
public class ClientFTP : MonoBehaviour
{
public UnityEngine.UI.Image label;
IEnumerator Start ()
{
// Create the connection and whait until it is established
string url = ("ftp://192.168.10.11/prova.png");
WWW ftpconnection = new WWW (url);
yield return ftpconnection;
// Download the image and render it as a texture
Texture2D tex = new Texture2D (250, 192);
ftpconnection.LoadImageIntoTexture (tex);
// Assign the texture to a new sprite
Sprite s = Sprite.Create (tex, new Rect (0, 0, 250f, 192f), new Vector2 (0.5f, 0.5f), 300);
label.preserveAspect = true;
label.sprite = s;
}
}
Your answer
Follow this Question
Related Questions
Download binary file from my FTP server 0 Answers
UTF-8 characters on Android build 1 Answer
Download progress is -1 forever. 2 Answers
Download file from ftp server not work on build release. 1 Answer