Advertisement
Guest User

Untitled

a guest
Mar 14th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. public void ExportJSON() {
  2.  
  3. string FTPHost = "ftp://xxx.xxxx.xxx/";
  4. string FTPUserName = "login";
  5. string FTPPassword = "pass";
  6. string FilePath;
  7.  
  8. if (Application.internetReachability == NetworkReachability.NotReachable) {
  9. Debug.Log ("Error. Check internet connection!");
  10. } else {
  11. try {
  12. FilePath = Path.Combine (Application.persistentDataPath, "clients.json");
  13. Debug.Log ("Path: " + FilePath);
  14.  
  15. WebClient client = new System.Net.WebClient ();
  16. Uri uri = new Uri (FTPHost + new FileInfo (FilePath).Name);
  17. Debug.Log (uri);
  18. client.UploadProgressChanged += new UploadProgressChangedEventHandler (OnFileUploadProgressChanged);
  19. client.UploadFileCompleted += new UploadFileCompletedEventHandler (OnFileUploadCompleted);
  20. client.Credentials = new System.Net.NetworkCredential (FTPUserName, FTPPassword);
  21. client.UploadFileAsync (uri, "STOR", FilePath);
  22. } catch {
  23. Debug.Log ("error");
  24. }
  25. }
  26.  
  27. }
  28.  
  29. void OnFileUploadProgressChanged(object sender, UploadProgressChangedEventArgs e) {
  30. Debug.Log("Uploading Progress: " + e.ProgressPercentage);
  31. }
  32.  
  33. void OnFileUploadCompleted(object sender, UploadFileCompletedEventArgs e) {
  34. Debug.Log("File Uploaded");
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement