Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by DDeathlonger · Aug 27, 2018 at 11:12 AM · downloaddownloadable contentftp

How do I Download FTPES Password Protected File in Background

I've been messing around with a lot of things in the last couple of weeks and can't seem to find the right way of doing this.. I'm doing this in Unity, but of course the essence should be maintainable within an environment.

I have 3 audio files and a Text Document on an FTPES that is to be clear Explicit TLS over FTP:

I have successfully logged in using the following code to verify the file's existence:

  WebRequest.RegisterPrefix("ftps", new FtpsWebRequestCreator());
     ftpRequest = (FtpWebRequest)WebRequest.Create("ftps://" + IP + "/" + fileEndPath);
     ftpRequest.Credentials = new NetworkCredential(User, Password);
     ftpRequest.Method = WebRequestMethods.Ftp.GetFileSize;
 
     ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateCertificate);
     ServicePointManager.Expect100Continue = true;
  
     ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
     ftpResponse.Close();
     ValidConnection = true;

This being said, I have also successfully downloaded the file a number of ways.. the issues I've had are as follows:

  • Using FtpWebRequest I can download file and used to be able to load the file as an AudioClip (I honestly don't know why it randomly stopped working, the downloading using ftpwebrequest that is...) using the WWW class, but because I could not seem to find a way to shove it into the background.. I tried writing to file using streamWriter, and it didn't seem to work.

  • Using UnityWebRequest I cannot log into a FTPS server as it is designed for HTTP based communications.

  • Using WebClient I was able to log in to the sever (by registering the prefix as shown above and associating it on the low level with the useSsl bool set to true) and
    • Using .DownloadFile not able to download file, hangs Unity Main Thread.

    • Using .DownloadFileAsyn able to download the the file, but have no read permission, and Complete event never gets called to continue into loading the file using WWW.

Where I am as of this post is using WebClient.DownloadFileAsyn:

 internal void Download(FileType fileType)
     {
         IsDownloading = true;
         if (ValidConnection)
         {
             try
             {
                 StartCoroutine(SetFileCreation());
 
                 using (WebClient client = new WebClient())
                 {
                     WebRequest.RegisterPrefix("ftps", new FtpsWebRequestCreator());
                     client.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
                     client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadFileProgressChanged);
                     client.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadFileCompleted);
                     client.DownloadFileAsync(ftpIP, Application.dataPath + "/StreamingAssets/" + ftpFilePath, fileType);
                 }
             }
             catch (WebException ex)
             {
                 Debug.LogError(ex.Message + ex.StackTrace + "\n");
             }
         }
         else
             IsDownloading = false;
     }

SetFileCreation(); is a method which verifies the location, and if it exists, overwrites, otherwise creates the directories before continuing.

Now I don't have any clean code (other than what I've shown) to show what I've been doing, but if some one could just either point me to a good example of this, (I've yet to find much on downloading from FTPS in Unity) or just share how they'd approach this issue from the ground up, it'd be much appreciated.

As a side note, I know my FTP server is functioning as intended via https://ftptest.net/ And my Server Logs (I host it myself, so I've full control of settings) show all correct messages all up to the RETR and Transfer Successful messages.

I've seen plenty of posts on FTPS, on Various ways to download inside of Unity and Outside, all the different levels of network communication; high level and low level, and how to load files from a folder into Unity in realtime. But nothing covering it all in one, nice and clean. KISS!

As most of us, I've got the bigger picture to focus on and can't let this detail continue to delay development.

Edit (Server Logs):

Here's the Server log from my WebClient.DownloadAsync();

 (000657)08/23/2018 22:51:32 - (not logged in) ([MyIP])> Connected, sending welcome message...
 (000657)08/23/2018 22:51:32 - (not logged in) ([MyIP])> AUTH TLS
 (000657)08/23/2018 22:51:32 - (not logged in) ([MyIP])> 234 Using authentication type TLS
 (000657)08/23/2018 22:51:32 - (not logged in) ([MyIP])> SSL connection established
 (000657)08/23/2018 22:51:32 - (not logged in) ([MyIP])> PBSZ 0
 (000657)08/23/2018 22:51:32 - (not logged in) ([MyIP])> 200 PBSZ=0
 (000657)08/23/2018 22:51:32 - (not logged in) ([MyIP])> PROT P
 (000657)08/23/2018 22:51:32 - (not logged in) ([MyIP])> 200 Protection level set to P
 (000657)08/23/2018 22:51:32 - (not logged in) ([MyIP])> USER Test
 (000657)08/23/2018 22:51:32 - (not logged in) ([MyIP])> 331 Password required for test
 (000657)08/23/2018 22:51:32 - (not logged in) ([MyIP])> PASS ********
 (000657)08/23/2018 22:51:32 - test ([MyIP])> 230 Logged on
 (000657)08/23/2018 22:51:32 - test ([MyIP])> OPTS utf8 on
 (000657)08/23/2018 22:51:32 - test ([MyIP])> 200 UTF8 mode enabled
 (000657)08/23/2018 22:51:32 - test ([MyIP])> PWD
 (000657)08/23/2018 22:51:32 - test ([MyIP])> 257 "/" is current directory.
 (000657)08/23/2018 22:51:32 - test ([MyIP])> CWD /
 (000657)08/23/2018 22:51:32 - test ([MyIP])> 250 CWD successful. "/" is current directory.
 (000657)08/23/2018 22:51:32 - test ([MyIP])> TYPE I
 (000657)08/23/2018 22:51:32 - test ([MyIP])> 200 Type set to I
 (000657)08/23/2018 22:51:32 - test ([MyIP])> PASV
 (000657)08/23/2018 22:51:32 - test ([MyIP])> 227 Entering Passive Mode ([MyIP],195,146)
 (000657)08/23/2018 22:51:32 - test ([MyIP])> RETR MainQuests.txt
 (000657)08/23/2018 22:51:32 - test ([MyIP])> 150 Connection accepted
 (000657)08/23/2018 22:51:32 - test ([MyIP])> SSL connection for data connection established
 (000657)08/23/2018 22:51:32 - test ([MyIP])> 226 Transfer OK

It's worth noting that the connection is maintained.. it does not close, because the connection is set to close after the file is finished downloading...

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

88 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How Export and Downloading Asset Bundle at runtime? 0 Answers

How to background download Addressable Assets System in iOS? 0 Answers

Addressables: PercentComplete did not started from 0 and suddenly reach 1 6 Answers

Download binary file from my FTP server 0 Answers

What is the download size of updating from version 2019.3 to 2019.4.1f1? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges