public static string FTP_DOWNLOAD(string arg) { string[] args = Program.argsConvertor(arg); if (Array.IndexOf<string>(args, "-h") != -1) return "ftp_download -url [ip/domain] -dir [folder path] -file [file name] -user [userame] -pass [password] -dst [destination path];\n" + "while the file name and folder doesn't start or end with /;"; if (args.Length < 12) return "not enough arguments"; try { string inputfilepath = args[Array.IndexOf<string>(args, "-dst") + 0x1]; if (inputfilepath[0] == '\\') inputfilepath = CurrentFolder.Substring(0, 2) + inputfilepath.Substring(1); else if (inputfilepath[1] != ':') inputfilepath = CurrentFolder + inputfilepath; string ftpHost = args[Array.IndexOf<string>(args, "-url") + 0x1]; string ftpDir = args[Array.IndexOf<string>(args, "-dir") + 0x1]; string ftpFile = args[Array.IndexOf<string>(args, "-file") + 0x1]; string username = args[Array.IndexOf<string>(args, "-user") + 0x1]; string password = args[Array.IndexOf<string>(args, "-pass") + 0x1]; string ftpfullpath = "ftp://" + ftpHost + '/' + (ftpDir != "/" ? ftpDir + '/' : string.Empty) + ftpFile; System.Net.WebClient request = new System.Net.WebClient(); request.Credentials = new System.Net.NetworkCredential(username, password); byte[] fileData = request.DownloadData(ftpfullpath); IO.FileStream file = IO.File.Create(inputfilepath); file.Write(fileData, 0, fileData.Length); file.Close(); return "downloaded file " + ftpfullpath + "\n" + "downloaded to " + inputfilepath + "\n" + "size(Bytes) = " + fileData.Length; } catch (Exception ex) { return "error:\n" + ex.ToString(); } }
public static string HTTP_Download(string arg) { string[] args = Program.argsConvertor(arg); if (args.Length < 4) return "not enough arguments"; string url = args[Array.IndexOf<string>(args, "-u") + 1]; string destination = args[Array.IndexOf<string>(args, "-d") + 1]; if (destination[0] == '\\') destination = CurrentFolder.Substring(0, 2) + destination.Substring(1); else if (destination[1] != ':') destination = CurrentFolder + destination; try { using (System.Net.WebClient Client = new System.Net.WebClient()) { Client.DownloadFile(url, destination); } return "downloaded to " + destination; } catch (Exception ex) { return "error\n" + ex.GetType(); } }
public static string SetDesktopImage(string arg) { if (arg.Contains("-h")) return SET_DESKTOP_IMAGE_COMMAND + " -u [image url] (-t [type])\nor\n" + SET_DESKTOP_IMAGE_COMMAND + " -f [image path] (-t [type])\n" + " the default type is 2 (streched)\n" + " types: 0 - Tiled; 1 - Centered"; string[] args = Program.argsConvertor(arg); string file_path = string.Empty; other.DesktopBackgroundChange.Style type; if (arg.Contains("-u")) { string uri = args[Array.IndexOf<string>(args, "-u") + 0x1].Replace('/', '\\'); string extension = uri.Split('\\')[uri.Split('\\').Length - 1]; System.IO.Stream s = new System.Net.WebClient().OpenRead(uri); System.Drawing.Image img = System.Drawing.Image.FromStream(s); string tempPath = IO.Path.Combine(IO.Path.GetTempPath(), "wallpaper." + extension); img.Save(tempPath); img.Dispose(); s.Close(); s.Dispose(); } else if (arg.Contains("-f")) file_path = args[Array.IndexOf<string>(args, "-f") + 0x1].Replace('/', '\\'); else return "bad filename"; if (arg.Contains("-t")) type = (other.DesktopBackgroundChange.Style)int.Parse(args[Array.IndexOf<string>(args, "-t") + 0x1]); else type = other.DesktopBackgroundChange.Style.Stretched; try { other.DesktopBackgroundChange.Set(file_path, type); return "ok!"; } catch (Exception ex) { return "error\n" + ex.ToString(); } }