コード例 #1
0
        string pegaArq()
        {
            String ftpServerIP = ConfigurationManager.AppSettings["ftpServerIP"];
            String ftpUserID   = ConfigurationManager.AppSettings["ftpUserID"];
            String ftpPassword = ConfigurationManager.AppSettings["ftpPassword"];



            /* Create Object Instance */
            // ftp ftpClient = new ftp(@"ftp://10.10.10.10/", "user", "password");
            ftp ftpClient = new ftp(ftpServerIP, ftpUserID, ftpPassword);

            /* Upload a File */
            ftpClient.upload("etc/test.txt", @"C:\Users\metastruct\Desktop\test.txt");

            /* Download a File */
            ftpClient.download("etc/test.txt", @"C:\Users\metastruct\Desktop\test.txt");

            /* Delete a File */
            ftpClient.delete("etc/test.txt");

            /* Rename a File */
            ftpClient.rename("etc/test.txt", "test2.txt");

            /* Create a New Directory */
            ftpClient.createDirectory("etc/test");

            /* Get the Date/Time a File was Created */
            string fileDateTime = ftpClient.getFileCreatedDateTime("etc/test.txt");

            Console.WriteLine(fileDateTime);

            /* Get the Size of a File */
            string fileSize = ftpClient.getFileSize("etc/test.txt");

            Console.WriteLine(fileSize);

            /* Get Contents of a Directory (Names Only) */
            string[] simpleDirectoryListing = ftpClient.directoryListDetailed("/etc");
            for (int i = 0; i < simpleDirectoryListing.Count(); i++)
            {
                Console.WriteLine(simpleDirectoryListing[i]);
            }

            /* Get Contents of a Directory with Detailed File/Directory Info */
            string[] detailDirectoryListing = ftpClient.directoryListDetailed("/etc");
            for (int i = 0; i < detailDirectoryListing.Count(); i++)
            {
                Console.WriteLine(detailDirectoryListing[i]);
            }
            /* Release Resources */
            ftpClient = null;

            return("ok");
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: Jaesun0314/FTP
        private void viewRemoteListView(FtpInfo info, ftp ftpClient, string remotePath)
        {
            string[] dirInfo    = ftpClient.directoryListDetailed(remotePath);
            string   dir_name   = string.Empty;
            string   dir_option = string.Empty;
            string   Temp       = string.Empty;

            txt_remothPath.Text = remotePath;

            if (listBox_Remote.Items.Count > 0)
            {
                listBox_Remote.Items.Clear();
            }
            listBox_Remote.Items.Add("..");

            foreach (string dir in dirInfo)
            {
                if (dir.Length > 1)
                {
                    //dir -> "drwxr-xr-x 1 ftp ftp              0 Sep 07 17:04 folder1"
                    dir_name   = dir.Substring(dir.LastIndexOf(':') + 4);
                    dir_option = dir.Substring(0, dir.IndexOf(' '));

                    if (dir_name.IndexOf('/') > 0)
                    {
                        Temp = dir_name.Substring(dir.LastIndexOf('/') + 1);
                        listBox_Remote.Items.Add(Temp);
                    }
                    else
                    {
                        listBox_Remote.Items.Add(dir_name);
                    }
                }
            }
        }
コード例 #3
0
        private void timer3_Tick(object sender, EventArgs e)
        {
            List <DateClass> dateList = new List <DateClass>();
            var uri = new Uri("ftp://" + confList["Server"]);
            /* Create Object Instance */
            ftp ftpClient = new ftp(uri.ToString(), confList["Username"], confList["Password"]);

            var dirStr = ftpClient.directoryListDetailed(confList["Fpath"]);

            if (dirStr.Count() > 3)
            {
                foreach (var item in dirStr)
                {
                    if (item != "")
                    {
                        var cdate = creationDate(item);
                        dateList.Add(cdate);
                    }
                }

                dateList.Sort(delegate(DateClass x, DateClass y)
                {
                    return(y.FullDate.CompareTo(x.FullDate));
                });

                //Using WinSCP for deleting directories
                string bareServer = confList["Server"].Split(':')[0];

                SessionOptions sessionOptions = new SessionOptions
                {
                    Protocol = Protocol.Ftp,
                    HostName = bareServer,
                    UserName = confList["Username"],
                    Password = confList["Password"],
                };
                sessionOptions.AddRawSettings("ProxyPort", "0");
                int sizeKeep = 1;
                sizeKeep = Convert.ToInt32(confList["Keep"]);

                for (int i = sizeKeep; i < dateList.Count; i++)
                {
                    using (Session session = new Session())
                    {
                        // Connect
                        session.Open(sessionOptions);

                        // Delete folder
                        session.RemoveFiles(confList["Fpath"] + "/" + dateList[i].Name).Check();
                    }
                    logs += "Directory:--" + dateList[i].Name + "-- was removed" + Environment.NewLine;
                    saveLog(logs);
                    textBox8.Text += logs;
                    logs           = "";
                }

                updateTreeView();
            }
        }
コード例 #4
0
ファイル: Form1.cs プロジェクト: mk30746/lab4_ftp
        private void button_connect_Click(object sender, EventArgs e)
        {
            string adres = textBox_adres.Text + ":" + textBox_port.Text + textBox_folder.Text;
            string login = textBox_login.Text;
            string haslo = textBox_password.Text;

            ftp ftpClient = new ftp(adres, login, haslo);

            string[] detailDirectoryListing = ftpClient.directoryListDetailed();
            for (int i = 0; i < detailDirectoryListing.Count(); i++)
            {
                textBox_log.AppendText(detailDirectoryListing[i]);
                textBox_log.AppendText("\r\n");
            }
            ftpClient = null;
        }