コード例 #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
    public void PostTOserver()
    {
        string imgPath   = Application.persistentDataPath + "/Initial/Default.png";
        ftp    ftpClient = new ftp(@"ftp://192.168.0.101/", "sling", "socialiot1212");

        Debug.Log("Image Path: " + imgPath);

        ftpClient.upload("Default.png", @imgPath);
        Debug.Log(ftpClient);
        /* Get the Size of a File */
        string fileSize = ftpClient.getFileSize("Default.png");

        Debug.Log(fileSize);
    }
コード例 #3
0
        static void ApplicationUpdater(string ftpHost, string ftpUser, string ftpPassword, string zipFile, string md5File, string filePath = "")
        {
            CultureInfo MyCultureInfo = new CultureInfo("en-US");
            ftp         ftpClient     = new ftp(@"ftp://" + ftpHost, ftpUser, ftpPassword);
            string      appPath       = Directory.GetCurrentDirectory() + @"\";
            string      updatePath    = Directory.GetCurrentDirectory() + @"\update\";

            if (filePath == "")
            {
                filePath = appPath;
            }
            //prepare update folder
            if (!Directory.Exists(updatePath))
            {
                Directory.CreateDirectory(updatePath);
            }
            else
            {
                DirectoryInfo dInfo = new DirectoryInfo(updatePath);
                //delete files:
                foreach (FileInfo file in dInfo.GetFiles())
                {
                    file.Delete();
                }
                //delete directories in this directory:
                foreach (DirectoryInfo subDirectory in dInfo.GetDirectories())
                {
                    subDirectory.Delete(true);
                }
            }
            //Get zip file
            ftpClient.download(mdlGlobal.ftpPath + zipFile, updatePath + zipFile);
            long ufSize = ftpClient.getFileSize(mdlGlobal.ftpPath + zipFile);

            if (ftpClient.error == null)
            {
                if (File.Exists(updatePath + zipFile))
                {
                    FileInfo fi         = new FileInfo(updatePath + zipFile);
                    long     dfSize     = fi.Length;
                    DateTime dfDateTime = fi.CreationTime;
                    if (dfSize == ufSize)
                    {
                        //Get MD5 file
                        ftpClient.download(mdlGlobal.ftpPath + md5File, updatePath + md5File);
                        if (ftpClient.error == null)
                        {
                            if (File.Exists(updatePath + md5File))
                            {
                                File.Copy(Path.Combine(appPath, "fciv.exe"), Path.Combine(updatePath, "fciv.exe"), true);
                                Directory.SetCurrentDirectory(updatePath);
                                //check MD5 hash file
                                //Create Process Start information
                                ProcessStartInfo processStartInfo = new ProcessStartInfo("fciv.exe", "-v -xml " + md5File);
                                processStartInfo.ErrorDialog            = false;
                                processStartInfo.UseShellExecute        = false;
                                processStartInfo.RedirectStandardError  = true;
                                processStartInfo.RedirectStandardInput  = true;
                                processStartInfo.RedirectStandardOutput = true;
                                //Execute the process
                                Process process = new Process();
                                process.StartInfo = processStartInfo;
                                bool processStarted = process.Start();
                                if (processStarted)
                                {
                                    //Get the output stream
                                    StreamReader outputReader = process.StandardOutput;
                                    StreamReader errorReader  = process.StandardError;
                                    process.WaitForExit();
                                    //Display the result
                                    string displayText = "Output" + Environment.NewLine + "==============" + Environment.NewLine;
                                    displayText += outputReader.ReadToEnd();
                                    displayText += Environment.NewLine + "Error" + Environment.NewLine + "==============" +
                                                   Environment.NewLine;
                                    displayText += errorReader.ReadToEnd();
                                    if (displayText.Contains("All files verified successfully"))
                                    {
                                        //extract zip file
                                        ZipFile.ExtractToDirectory(updatePath + zipFile, updatePath + @"\extract");
                                        //using (var zipFileList = new ZipFile(updatePath + zipFile))
                                        //{
                                        //    zipFileList.ExtractAll(updatePath + @"\extract");
                                        //}

                                        //copy to extract files
                                        string sourceDir = updatePath + @"\extract";
                                        try
                                        {
                                            string[] fileList = Directory.GetFiles(sourceDir, "*.*");
                                            foreach (string f in fileList)
                                            {
                                                // Remove path from the file name.
                                                string fName = f.Substring(sourceDir.Length + 1);
                                                // Use the Path.Combine method to safely append the file name to the path.
                                                // Will overwrite if the destination file already exists.
                                                File.Copy(Path.Combine(sourceDir, fName), Path.Combine(filePath, fName), true);
                                            }
                                        }
                                        catch (DirectoryNotFoundException dirNotFound)
                                        {
                                            MessageBox.Show(dirNotFound.Message);
                                        }
                                    }
                                }
                                Directory.SetCurrentDirectory(appPath);
                            }
                        }
                    }
                }
            }
            ftpClient = null;
        }