Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6. using System.Net;
  7. using System.Web;
  8.  
  9. namespace GMOD_Lua_Cache
  10. {
  11. class Program
  12. {
  13. private static string addr;
  14. private static string user;
  15. private static string pass;
  16. private static string path;
  17. static void Main(string[] args)
  18. {
  19. Console.WriteLine("GMOD Lua Auto Cache\nAutomaticly update your cache!\n\n");
  20. Console.Title = "GMOD Auto Lua Cache";
  21.  
  22. try
  23. {
  24. StreamReader settings = new StreamReader("settings.txt");
  25.  
  26. user = settings.ReadLine();
  27. pass = settings.ReadLine();
  28. path = settings.ReadLine();
  29. addr = settings.ReadLine();
  30.  
  31. settings.Close();
  32. settings.Dispose();
  33.  
  34. Console.WriteLine("Local DIR: " + path);
  35. Console.WriteLine("Remote Address: " + addr + "\n\n");
  36.  
  37. FileSystemWatcher watcher = new FileSystemWatcher();
  38. watcher.Path = path;
  39. watcher.Filter = "*.dua";
  40.  
  41. //watcher.Created += new FileSystemEventHandler(Created);
  42. watcher.Changed += new FileSystemEventHandler(Created);
  43. watcher.EnableRaisingEvents = true;
  44.  
  45. while (true)
  46. {
  47. System.Threading.Thread.Sleep(500);
  48. }
  49. }
  50. catch (Exception ex)
  51. {
  52. Console.WriteLine("ERROR: settings.txt is either corrupt or non-existent");
  53. Console.WriteLine("settings.txt format:\nFTP User\nFTP Password\nLocal Cache Folder\nRemote Cache Folder\n\nAn Example would be:\n\nmyuser123\nmypassword\nC:\\Server\\orangebox\\garrysmod\\cache\\\nftp://myfastdlwebsite.com/dir/cache/\n\nPlease note that all paths must end with a slash");
  54. Console.ReadKey(true);
  55. return;
  56. }
  57. }
  58.  
  59. private static void Created(object obj, FileSystemEventArgs e)
  60. {
  61. Console.WriteLine(e.Name + " has changed.");
  62.  
  63. try
  64. {
  65. FtpWebRequest req = (FtpWebRequest)FtpWebRequest.Create(addr + e.Name); // create and caste it!
  66. req.Method = WebRequestMethods.Ftp.UploadFile;
  67. req.Credentials = new NetworkCredential(user, pass);
  68. req.UsePassive = true;
  69. req.UseBinary = true;
  70. req.KeepAlive = false;
  71.  
  72. FileStream stream = new FileStream(e.FullPath, FileMode.Open);
  73. byte[] buff = new byte[stream.Length];
  74. stream.Read(buff, 0, buff.Length);
  75. stream.Close();
  76.  
  77. Stream req_stream = req.GetRequestStream();
  78. req_stream.Write(buff, 0, buff.Length);
  79. req_stream.Close();
  80.  
  81. FtpWebResponse response = (FtpWebResponse)req.GetResponse();
  82. Console.WriteLine("Upload File Complete.\n{0}", response.StatusDescription);
  83. response.Close();
  84. }
  85. catch(Exception ex)
  86. {
  87. Console.WriteLine("ERROR: " + ex.Message);
  88. Console.WriteLine("Please make sure all of your details are correct\n");
  89. }
  90. }
  91. }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement