Advertisement
Guest User

Untitled

a guest
Oct 1st, 2010
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. susing 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!\nCreated by C0BRA\nXiaTek.org\n(c) Mitchel Collins 2010\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.  
  33. Console.WriteLine("Local DIR: " + path);
  34. Console.WriteLine("Remote Address: " + addr + "\n\n");
  35.  
  36. FileSystemWatcher watcher = new FileSystemWatcher();
  37. watcher.Path = path;
  38. watcher.Filter = "*.dua";
  39.  
  40. //watcher.Created += new FileSystemEventHandler(Created);
  41. watcher.Changed += new FileSystemEventHandler(Created);
  42. watcher.EnableRaisingEvents = true;
  43.  
  44. while (true)
  45. {
  46. System.Threading.Thread.Sleep(500);
  47. }
  48. }
  49. catch (Exception ex)
  50. {
  51. Console.WriteLine("ERROR: settings.txt is either corrupt or non-existent");
  52. 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");
  53. Console.ReadKey(true);
  54. return;
  55. }
  56. }
  57.  
  58. private static void Created(object obj, FileSystemEventArgs e)
  59. {
  60. Console.WriteLine(e.Name + " has changed.");
  61.  
  62. try
  63. {
  64. FtpWebRequest req = (FtpWebRequest)FtpWebRequest.Create(addr + e.Name); // create and caste it!
  65. req.Method = WebRequestMethods.Ftp.UploadFile;
  66. req.Credentials = new NetworkCredential(user, pass);
  67. req.UsePassive = true;
  68. req.UseBinary = true;
  69. req.KeepAlive = false;
  70.  
  71. FileStream stream = new FileStream(e.FullPath, FileMode.Open);
  72. byte[] buff = new byte[stream.Length];
  73. stream.Read(buff, 0, buff.Length);
  74. stream.Close();
  75.  
  76. Stream req_stream = req.GetRequestStream();
  77. req_stream.Write(buff, 0, buff.Length);
  78. req_stream.Close();
  79.  
  80. FtpWebResponse response = (FtpWebResponse)req.GetResponse();
  81. Console.WriteLine("Upload File Complete.\n{0}", response.StatusDescription);
  82. response.Close();
  83. }
  84. catch(Exception ex)
  85. {
  86. Console.WriteLine("ERROR: " + ex.Message);
  87. Console.WriteLine("Please make sure all of your details are correct\n");
  88. }
  89. }
  90. }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement