- Home /
Download from FTP with Hololens?
Hi everybody,
I would like to download files from a FTP-Server and do some magic with the data.
The application should run on the Microsoft Hololens. I am using Unity 2017.2 with the MixedRealityToolkit "2017.2.1.1 Patch Release".
In Unity everything works fine, but as soon as I try to build the application I receive 5 errors like: "The type or namespace name "FtpWebRequest" could not be found (are you missing a using directive orassembly reference?)"
I am using the Runtime Version "Experimental (.NET 4.6. Equivalent)" and the Api Compability Level ".NET 4.6"
This is the code of my main script:
using UnityEngine;
using System.IO;
using System.Net;
using System;
public class UpdateFtfFtp : MonoBehaviour
{
public float JsonReadInterval = 1;
public int AgvNumber;
private const string Host = "ftp://192.168.2.101/";
private string _remoteFileName;
private string _localFileName;
private const int bufferSize = 2048;
// JSON coords are in mm, table dimension is 2000mm x 1000mm
// Y axis on the table corresponds to Z axis on the map
// 0, 0 is at -0.036, 0.442 (local) on the map
// 2000, 1000 is at -0.526, 0.131 (local) on the map
// (assuming real coords are in the center of the FTF)
// This results in the following ratios for translating real to virtual coords
private const float ZeroX = -0.036F;
private const float ZeroY = 0.442F;
private const float RatioX = -0.000245F;
private const float RatioY = -0.000311F;
private float _timer;
// Use this for initialization
public void Start()
{
_remoteFileName = "AGV" + AgvNumber + "Status.json";
_localFileName = "Assets\\JsonStream\\" + _remoteFileName;
LoadJsonData();
}
// Update is called once per frame
public void Update()
{
_timer += Time.deltaTime;
if (_timer >= JsonReadInterval)
{
LoadJsonData();
_timer = 0;
}
}
private void LoadJsonData()
{
DownloadJson();
var jsonString = File.ReadAllText(_localFileName);
var ftfData = FtfData.FromJson(jsonString, AgvNumber);
transform.eulerAngles = new Vector3(0, 0, ftfData.Gyro);
transform.localPosition = new Vector3(
ZeroX + RatioX * ftfData.PosX,
transform.localPosition.y,
ZeroY + RatioY * ftfData.PosY
);
}
private void DownloadJson()
{
var request = (FtpWebRequest)WebRequest.Create(Host + _remoteFileName);
request.Credentials = new NetworkCredential("pi", "123");
request.Method = WebRequestMethods.Ftp.DownloadFile;
var response = (FtpWebResponse)request.GetResponse();
var ftpStream = response.GetResponseStream();
var localFileStream = new FileStream(_localFileName, FileMode.Create);
var byteBuffer = new byte[bufferSize];
var bytesRead = ftpStream.Read(byteBuffer, 0, bufferSize);
try
{
while (bytesRead > 0)
{
localFileStream.Write(byteBuffer, 0, bytesRead);
bytesRead = ftpStream.Read(byteBuffer, 0, bufferSize);
}
}
catch (Exception ex)
{
Debug.Log(ex.ToString());
}
localFileStream.Close();
ftpStream.Close();
response.Close();
request = null;
}
}
Do you know if it's possible to request data from a FTP-Server with the Hololens?
All errors seem to be related to missing type or namespaces, in particular multiple errors from the System.Net namespace. Is it possible that I am missing a DLL or that the HoloLens does not support some libraries?
I am glad for any help. :)
Your answer
Follow this Question
Related Questions
Issue With System.Net when Using FTP 1 Answer
Issue with TLS and X509 authentication 0 Answers
Problem with FileStream 1 Answer
30f + 0.5f = 30f What?????? 1 Answer