Hello.
Unfortunately, I have never worked with FTP inside Unity.
I have looked at some examples for C#, but they don't work.
It is very easy to add third party source support in Smart Gallery.
You just need to implement your own content type, and select it in the gallery.
Example (doesn't work, but if you are already successfully downloading files via FTP, you can fix it):
using System.Collections;
using System.IO;
using System.Net;
using InfinityCode.SmartGallery.Modules;
using UnityEngine;
namespace InfinityCode.SmartGallery.ContentTypes
{
public class FtpTextureContent: RawImageContent
{
public string url;
public string login;
public string password;
public override bool allowZoom => true;
public override string name => "Ftp Texture";
protected override void LoadContentData(Content content)
{
contentRawImage.enabled = false;
messageSystem.SetLoadingState?.Invoke(true);
content.viewer.StartCoroutine(LoadCoroutine());
}
private IEnumerator LoadCoroutine()
{
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(url);
request.Method = WebRequestMethods.Ftp.DownloadFile;
request.Credentials = new NetworkCredential(login, password);
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
byte[] bytes = new byte[responseStream.Length];
reader.BaseStream.Read(bytes, 0, bytes.Length);
Texture2D texture = new Texture2D(2, 2);
texture.LoadImage(bytes);
if (texture == null)
{
messageSystem.SetLoadingState?.Invoke(false);
Debug.LogError("Texture is null.");
yield break;
}
contentRawImage.texture = texture;
contentRectTransform.sizeDelta = new Vector2(texture.width, texture.height);
content.InitContentSize();
content.AdjustSize();
messageSystem.SetLoadingState?.Invoke(false);
}
protected override bool ValidateProperties()
{
return true;
}
}
}
Kind Regards,
Infinity Code Team.
Boost your productivity a lot and immediately using
Ultimate Editor Enhancer.
Trial and non-commerce versions available.