Beispiel #1
0
            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();
                }
            }