Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- susing System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- using System.Net;
- using System.Web;
- namespace GMOD_Lua_Cache
- {
- class Program
- {
- private static string addr;
- private static string user;
- private static string pass;
- private static string path;
- static void Main(string[] args)
- {
- Console.WriteLine("GMOD Lua Auto Cache\nAutomaticly update your cache!\nCreated by C0BRA\nXiaTek.org\n(c) Mitchel Collins 2010\n\n");
- Console.Title = "GMOD Auto Lua Cache";
- try
- {
- StreamReader settings = new StreamReader("settings.txt");
- user = settings.ReadLine();
- pass = settings.ReadLine();
- path = settings.ReadLine();
- addr = settings.ReadLine();
- settings.Close();
- Console.WriteLine("Local DIR: " + path);
- Console.WriteLine("Remote Address: " + addr + "\n\n");
- FileSystemWatcher watcher = new FileSystemWatcher();
- watcher.Path = path;
- watcher.Filter = "*.dua";
- //watcher.Created += new FileSystemEventHandler(Created);
- watcher.Changed += new FileSystemEventHandler(Created);
- watcher.EnableRaisingEvents = true;
- while (true)
- {
- System.Threading.Thread.Sleep(500);
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine("ERROR: settings.txt is either corrupt or non-existent");
- 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");
- Console.ReadKey(true);
- return;
- }
- }
- private static void Created(object obj, FileSystemEventArgs e)
- {
- Console.WriteLine(e.Name + " has changed.");
- try
- {
- FtpWebRequest req = (FtpWebRequest)FtpWebRequest.Create(addr + e.Name); // create and caste it!
- req.Method = WebRequestMethods.Ftp.UploadFile;
- req.Credentials = new NetworkCredential(user, pass);
- req.UsePassive = true;
- req.UseBinary = true;
- req.KeepAlive = false;
- FileStream stream = new FileStream(e.FullPath, FileMode.Open);
- byte[] buff = new byte[stream.Length];
- stream.Read(buff, 0, buff.Length);
- stream.Close();
- Stream req_stream = req.GetRequestStream();
- req_stream.Write(buff, 0, buff.Length);
- req_stream.Close();
- FtpWebResponse response = (FtpWebResponse)req.GetResponse();
- Console.WriteLine("Upload File Complete.\n{0}", response.StatusDescription);
- response.Close();
- }
- catch(Exception ex)
- {
- Console.WriteLine("ERROR: " + ex.Message);
- Console.WriteLine("Please make sure all of your details are correct\n");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement