Exemplo n.º 1
0
        private void btnTest_Click(object sender, EventArgs e)
        {
            ftp ftpClient = new ftp(@"ftp://" + txtIP.Text + "/", txtUsername.Text, txtPassword.Text);

            try
            {
                Boolean flag = ftpClient.isConnected();
                if (flag == true)
                {
                    MessageBox.Show("Connection is succesed");
                }
                else
                {
                    MessageBox.Show("Connection is failed");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            ftpClient = null;

            //obj = new FileUploaderThread();
            //Thread thr = new Thread(new ThreadStart(obj.run));
            //thr.Start();
        }
Exemplo n.º 2
0
        public void run()
        {
            String record_path = "";
            String ip = "", username = "", password = "";

            try
            {
                StreamReader sr = new StreamReader("C:\\config.txt");

                String val = sr.ReadLine();

                String[] value_list = val.Split('|');
                if (value_list.Length > 0)
                {
                    ip = value_list[0];
                }

                if (value_list.Length > 1)
                {
                    username = value_list[1];
                }

                if (value_list.Length > 2)
                {
                    password = value_list[2];
                }

                record_path = sr.ReadLine();

                //close the file
                sr.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            ftpClient = new ftp(@"ftp://" + ip + "/", username, password);

            while (m_bRunning)
            {
                try
                {
                    DateTime now = DateTime.Now;

                    string[] files = Directory.GetFiles(record_path);
                    foreach (string file in files)
                    {
                        if (IsFileLocked(file))
                        {
                            continue;
                        }

                        String filename = Path.GetFileName(file);

                        String upload_path = now.Year + "";
                        ftpClient.createDirectory(upload_path);
                        upload_path += "/" + now.Month;
                        ftpClient.createDirectory(upload_path);
                        upload_path += "/" + now.Day;
                        ftpClient.createDirectory(upload_path);
                        upload_path += "/" + filename;

                        ftpClient.upload(upload_path, file);

                        File.Delete(file);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }

                Thread.Sleep(60 * 1000);
            }
            ftpClient = null;
        }