Beispiel #1
0
 private void Button1_Click(object sender, EventArgs e)
 {
     ServerFilesTree.Nodes.Clear();
     FtpConnection                = new FluentFTP.FtpClient(HostNameTextBox.Text);
     FtpConnection.Encoding       = Encoding.UTF8;
     FtpConnection.ConnectTimeout = 10000;
     if (UsernameTextBox.Text != "")
     {
         FtpConnection.Credentials = new NetworkCredential(UsernameTextBox.Text, PasswordTextBox.Text);
     }
     try
     {
         FtpConnection.Connect();
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error Connecting");
         MessageBox.Show("Error: \n " + ex.Message);
         return;
     }
     MessageBox.Show("Conected");
     WorkingDirectory = "/";
     ServerFilesTree.Nodes.Add("/");
     ServerFilesTree.Nodes[0].Tag = "/";
     foreach (FluentFTP.FtpListItem Item in FtpConnection.GetListing(WorkingDirectory))
     {
         ServerFilesTree.Nodes[0].Nodes.Add(Item.FullName.Replace(WorkingDirectory, ""));
         ServerFilesTree.Nodes[0].LastNode.Tag = Item.FullName;
         //MessageBox.Show("Item Name: " + ServerFilesTree.Nodes[0].LastNode.Text);
         //MessageBox.Show("Item Tag: " + ServerFilesTree.Nodes[0].LastNode.Tag);
     }
 }
Beispiel #2
0
        private void ConnectTo()
        {
            try
            {
                AddEditWindow addEditWindow = new AddEditWindow();
                if (addEditWindow.model.ReturnCommand?.ToLower() == "ok")
                {
                    if (client.IsConnected)
                    {
                        client.Disconnect();
                    }

                    var customConfig = addEditWindow.model.SelectedItem;

                    if (customConfig == null || !customConfig.CanTryConnect)
                    {
                        return;
                    }

                    client = new FluentFTP.FtpClient(customConfig.HostName, int.Parse(customConfig.Port), customConfig.UserName, customConfig.Password);
                    client.Connect();
                    ListCombine(customConfig.RemoteFolder ?? "");
                    StatusText = "Connected";
                }
            }
            catch (Exception exc)
            {
                ToolsLib.Tools.ExceptionLogAndShow(exc, "ConnectTo");
            }
        }
Beispiel #3
0
 public void changePermissions(string Path, string Permissions, string HostName, string UserName, string Password)
 {
     FluentFTP.FtpClient client = new FluentFTP.FtpClient(HostName);
     client.Credentials = new NetworkCredential(UserName, Password);
     client.Connect();
     client.Chmod(Path, Convert.ToInt32(Permissions));
     client.Disconnect();
 }
Beispiel #4
0
 private FluentFTP.FtpClient GetFtpClient()
 {
     if (ftp == null)
     {
         ftp = new FluentFTP.FtpClient
         {
             Host        = host,
             Credentials = new System.Net.NetworkCredential(user, password),
         };
     }
     if (!ftp.IsConnected)
     {
         ftp.Connect();
     }
     return(ftp);
 }
Beispiel #5
0
        static void TestClient()
        {
            string host     = ConfigurationManager.AppSettings["FTP_HOST"];
            int    port     = int.Parse(ConfigurationManager.AppSettings["FTP_PORT"]);
            string username = ConfigurationManager.AppSettings["FTP_USERNAME"];
            string password = ConfigurationManager.AppSettings["FTP_PASSWORD"];

            using (FileStream stream = File.Open("C:\\ftp.txt", FileMode.Open))
            {
                FluentFTP.FtpClient client = new FluentFTP.FtpClient(host, port, username, password);

                client.Connect();
                client.Upload(stream, $"/ftp.txt", FluentFTP.FtpExists.Overwrite, true);
                client.Disconnect();

                stream.Close();
            }
        }
Beispiel #6
0
 public void runFluent(int command)
 {
     //0 = change permissions
     if (command == 0)
     {
         try
         {
             FluentFTP.FtpClient client = new FluentFTP.FtpClient(this.connection.ServerName);
             client.Credentials = new System.Net.NetworkCredential(this.connection.UserName, this.connection.PassWord);
             client.Connect();
             client.Chmod(this.path, this.permission);
             client.Disconnect();
         }
         catch (Exception e)
         {
             throw e;
         }
     }
 }
Beispiel #7
0
        private void Connect()
        {
            try
            {
                if (ConfigData == null || !ConfigData.CanTryConnect)
                {
                    return;
                }

                client = new FluentFTP.FtpClient(ConfigData.HostName, int.Parse(ConfigData.Port), ConfigData.UserName, ConfigData.Password);
                client.Connect();
                ListCombine(ConfigData.RemoteFolder ?? "");
                StatusText         = "Connected";
                ConfigData.LastUse = DateTime.Now;
            }
            catch (Exception)
            {
                MessageBox.Show("Can't connect");
            }
        }
Beispiel #8
0
        static void SaveFileToFtp(string sessionId, string userId, string toSave, string extName)
        {
            string filename = ConfigurationManager.AppSettings["SSO_ROOT"] + sessionId;

            string host       = ConfigurationManager.AppSettings["FTP_HOST"];
            int    port       = int.Parse(ConfigurationManager.AppSettings["FTP_PORT"]);
            string username   = ConfigurationManager.AppSettings["FTP_USERNAME"];
            string password   = ConfigurationManager.AppSettings["FTP_PASSWORD"];
            string remoteRoot = ConfigurationManager.AppSettings["REMOTE_ROOT"];

            using (FileStream stream = File.Open(filename, FileMode.Open))
            {
                FluentFTP.FtpClient client = new FluentFTP.FtpClient(host, port, username, password);

                client.Connect();
                client.Upload(stream, $"{remoteRoot}{userId}/{userId}_{toSave}_{DateTime.Now.ToString("yyyyMMddHHmmss")}.{extName}", FluentFTP.FtpExists.Overwrite, true);
                client.Disconnect();

                stream.Close();
            }

            File.Delete(filename);
        }
        public void SendCmd(string arg, bool user = false)
        {
            if (user)
            {
                log.Add(arg);
            }

            List <string> args    = arg.Split(' ').ToList();
            string        command = args[0];

            string GetArgs(int index, int to = -1)
            {
                string data = "";

                if (to == -1)
                {
                    to = 999999999;
                }
                for (int i = 0; i < args.Count; i++)
                {
                    if (i >= index && i <= to)
                    {
                        data += args[i] + " ";
                    }
                }
                return(data.TrimEnd());
            }

            if (arg.Split(' ')[0] == "echocl")
            {
                string color = arg.Split(' ')[1];
                Add(GetArgs(2), Color.FromName(color));
                return;
            }
            if (arg.Split(' ')[0] == "echoclcode")
            {
                try
                {
                    int R = Convert.ToInt32(arg.Split(' ')[1]);
                    int G = Convert.ToInt32(arg.Split(' ')[2]);
                    int B = Convert.ToInt32(arg.Split(' ')[3]);
                    Add(GetArgs(4), Color.FromArgb(R, G, B));
                }
                catch (Exception ex) { ResultsList.FromException(ex); }
                return;
            }
            if (arg.Split(' ')[0] == "echo")
            {
                Add(GetArgs(1));
                return;
            }
            if (arg.Split(' ')[0] == "ln")
            {
                if (GetArgs(1) == password)
                {
                    Add("Logged In!", Color.Lime);
                    login = true;
                    return;
                }
                if (GetArgs(1) == "logout")
                {
                    Add("Logged Out!", Color.Red);
                    login = false;
                    return;
                }
                Add("Bad Password!", Color.Red);
                return;
            }

            Add(" - " + arg, Color.Yellow);

            if (arg.Split(' ')[0] == "cd")
            {
                bool inoe = false;
                try
                {
                    var tmp = arg.Split(' ')[1];
                    if (tmp == " ")
                    {
                        inoe = true;
                    }
                }
                catch { inoe = true; }
                if (inoe)
                {
                    List <FluentFTP.FtpListItem> items = FTPHandle.GetItemsList("/ScreenShot");
                    Add("Items In Dir : Main : ");
                    for (int i = 0; i < items.Count; i++)
                    {
                        Add(items[i].Name, Color.Violet);
                    }
                }
                else
                {
                    List <FluentFTP.FtpListItem> items = FTPHandle.GetItemsList("/ScreenShot/" + arg.Split(' ')[1]);
                    Add("Items In Dir : " + arg.Split(' ')[1] + " : ");
                    for (int i = 0; i < items.Count; i++)
                    {
                        Add(items[i].Name, Color.Violet);
                    }
                }
                return;
            }
            if (arg.Split(' ')[0] == "wshmax")
            {
                if (login)
                {
                    try
                    {
                        wikipediamax = Convert.ToInt32(arg.Split(' ')[1]);
                        Add("Limit set to " + wikipediamax.ToString(), Color.Lime);
                    }
                    catch
                    {
                        return;
                    }

                    return;
                }
            }
            if (arg.Split(' ')[0] == "color")
            {
                try
                {
                    if (arg.Split(' ')[1] == "1" || arg.Split(' ')[1] == "0")
                    {
                        if (arg.Split(' ')[1] == "1")
                        {
                            color = true;
                        }
                        if (arg.Split(' ')[1] == "0")
                        {
                            color = false;
                        }
                        Add("Color is " + color.ToString(), Color.Lime);
                    }
                    richTextBox1.Visible = color;
                    richTextBox2.Visible = !color;
                    richTextBox2.Text    = richTextBox1.Text;
                    richTextBox2.SelectAll();
                    richTextBox2.SelectionColor = Color.Gray;
                    richTextBox2.DeselectAll();
                }
                catch
                {
                    return;
                }

                return;
            }
            if (arg.Split(' ')[0] == "wsearch" || arg.Split(' ')[0] == "wsh")
            {
                if (login)
                {
                    string querry = GetArgs(1);
                    try
                    {
                        Add("Searching : " + querry, Color.Aqua);
                        List <Search> searches  = new List <Search>();
                        Wikipedia     wikipedia = new Wikipedia(WikipediaNet.Enums.Language.Polish);
                        wikipedia.Limit = wikipediamax;
                        QueryResult   result  = wikipedia.Search(querry);
                        List <string> results = new List <string>();
                        foreach (Search s in result.Search)
                        {
                            searches.Add(s);
                            results.Add(s.Snippet);
                        }

                        for (int i = 0; i < results.Count; i++)
                        {
                            results[i] = results[i].Replace("<span class=\"searchmatch\">", "");
                            results[i] = results[i].Replace("</span>", "");
                        }
                        for (int i = 0; i < results.Count; i++)
                        {
                            Add(results[i], Color.Violet);
                        }
                    }
                    catch (Exception ex) { Add(ex.ToString()); }
                    return;
                }
            }
            if (arg.Split(' ')[0] == "clear" || arg.Split(' ')[0] == "cs")
            {
                richTextBox1.Text = "";
                log.Clear();
                return;
            }
            if (arg.Split(' ')[0] == "credentials")
            {
                if (args.Count > 1)
                {
                    if (args[1] == "reset")
                    {
                        FTPHandle.credential.Password = FTPHandle.haslo;
                        FTPHandle.credential.UserName = FTPHandle.login;
                        FTPHandle.adres = FTPHandle.adresfactory;
                        Add("Credentials changed to factory", Color.Violet);
                    }
                    if (args[1] == "ping")
                    {
                        try
                        {
                            FluentFTP.FtpClient f = new FluentFTP.FtpClient(FTPHandle.adres, FTPHandle.credential);
                            f.Connect();
                            f.Disconnect();
                            Add("Credentials ping succes", Color.Lime);
                        }
                        catch (Exception ex) { ResultsList.FromException(ex); Add("To reset write : credentials reset", Color.Violet); }
                        return;
                    }
                    if (args[1] == "changepass")
                    {
                        FTPHandle.credential.Password = GetArgs(2);
                        Add("Password changed to : " + GetArgs(2), Color.Violet);
                    }
                    if (args[1] == "changelogin")
                    {
                        FTPHandle.credential.UserName = GetArgs(2);
                        Add("Login changed to        : " + GetArgs(2), Color.Violet);
                    }
                    if (args[1] == "changehost")
                    {
                        FTPHandle.adres = GetArgs(2);
                        Add("Host changed to         : " + GetArgs(2), Color.Violet);
                    }
                }
                Add("Login Credentials", Color.Yellow);
                Add("Host         : " + FTPHandle.adres, Color.Violet);
                Add("Login        : "******"Password : "******"";
                for (int i = 0; i < FTPHandle.credential.Password.Length; i++)
                {
                    passhide += "*";
                }
                if (!login)
                {
                    Add("Password : "******"Null Command", Color.Red);
        }
Beispiel #10
0
 public void Connect()
 {
     _client.Connect();
 }
 public override void Connect()
 {
     _client.Connect();
     OnPropertyChanged("IsConnected");
 }