- Home /
Question by
adamhusain12 · Sep 20, 2018 at 01:42 PM ·
serverdownloadbinaryfilestreamftp
Download binary file from my FTP server
Hi Guys! I want to download a binary file from my FTP server and extract the class data. I have written the code but there seems to be an error. Can you please help me with this. Here's the code:
public class FileDownload : MonoBehaviour
{
XYZ data;
FileSave Vars;
public string FTPHost = "ftp://files.myserver.com";
public string FTPUserName = "username";
public string FTPPassword = "password";
public void Download()
{
BinaryFormatter BF = new BinaryFormatter();
WebClient client = new System.Net.WebClient();
Uri uri = new Uri(FTPHost + '/' + "ABC.dat");
client.Credentials = new System.Net.NetworkCredential(FTPUserName, FTPPassword);
byte[] DATA = client.DownloadData(uri);
Stream stream = new MemoryStream(DATA);
data = (XYZ)BF.Deserialize(stream);
Vars.A = data.X;
Vars.B = data.Y;
}
}
Comment
Your answer
Follow this Question
Related Questions
Unable to connect to remote server when downloading from FTP 0 Answers
How to Retrieve List of Files on FTP Server 2 Answers
Download file from ftp server not work on build release. 1 Answer
Asset Bundles download at runtime 1 Answer
FileStream on separate Thread seems to block the main thread 1 Answer