コード例 #1
0
    public void DownloadFileFromUploads(string filename)
    {
        ftp ftpClient = new ftp("ftp://xo2.x10hosting.com/public_html/Uploads/", "dioramaw", "1qaz@WSX3edc$RFV");

        ftpClient.download(filename, Globals.TEMPFOLDER + filename);
        ftpClient = null;
    }
コード例 #2
0
//	EXAMPLE
//	/* Create Object Instance */
//	ftp ftpClient = new ftp("ftp://10.10.10.10/", "user", "password");
//
//	/* 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;


    public void ReadFromFTP(string ftpPathToFile, string localPathToSave)
    {
//		ftp ftpClient = new ftp("ftp://en1372.mirohost.net/", "Math4Ami", "dXf8E7nl01dGLz");
        ftp ftpClient = new ftp("ftp://en1372.mirohost.net/", "Math2AmiTest", "Glj946ra2Hqm");

        ftpClient.download(ftpPathToFile, localPathToSave);
    }
コード例 #3
0
ファイル: Program.cs プロジェクト: dromero88/FTPTools
        static void Main(string[] args)
        {
            try
            {
                if (global.config.exist())
                {
                    global.config config = new global.config();
                    sharedOP.WriteToLog("Inicio de FTPTools:" + global.config.descripcion, "Tarea iniciada con exito");
                    ftp oFtp = new ftp(global.config.sftp, global.config.user, global.config.pass, global.config.proxy_user, global.config.proxy_pass, global.config.useproxy);

                    Console.WriteLine("/**********FTPTOOLS*************/");
                    Console.WriteLine("Fichero:" + global.config.fichero);
                    Console.WriteLine("Ftp:" + global.config.sftp);

                    if (global.config.action == "download")
                    {
                        Console.WriteLine("Accion:" + global.config.action);
                        oFtp.download(global.config.fichero, global.config.rutLocal + "/" + global.config.fichero);
                        sharedOP.WriteToLog("Download", "Descarga de " + global.config.fichero + " realizada correctamente");
                    }
                    if (global.config.action == "upload")
                    {
                        Console.WriteLine("Accion:" + global.config.action);
                        oFtp.upload(global.config.fichero, global.config.rutLocal + "/" + global.config.fichero);
                        sharedOP.WriteToLog("Upload", "Subida de " + global.config.fichero + " realizada correctamente");
                    }
                }
                else
                {
                    global.Errores.add(new Exception("No se encuentra el fichero de configuración"));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("/**********ERRORES*************/");
                Console.WriteLine("Error: " + ex.Message.ToString());
                Console.WriteLine("StackTrace: " + ex.StackTrace);
                global.Errores.add(ex);
            }

            if (global.Errores.getNuErrores() >= 1)
            {
                global.Errores.writeLog();
                //global.Errores.sendEmail();
                //Envio por ASPMail que va bastante mejor que la caca de microsoft
                if (global.config.emailTipo == "EmailAgent")
                {
                    global.Errores.sendEmailAgent();
                }
                else if (global.config.emailTipo == "SmtpFramework")
                {
                    global.Errores.sendEmail();
                }
                else
                {
                    global.Errores.sendEmail();
                }
            }
        }
コード例 #4
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");
        }
コード例 #5
0
    public void DownloadRandomFile()
    {
        ftp ftpClient = new ftp("ftp://xo2.x10hosting.com/public_html/Uploads/", "dioramaw", "1qaz@WSX3edc$RFV");

        string[] simpleDirectoryListing = ftpClient.directoryListSimple("/");
        //UpdateLog("Number of uploaded Dioramas: " + (simpleDirectoryListing.Length - 2));
        int i = UnityEngine.Random.Range(2, simpleDirectoryListing.Length - 1);

        ftpClient.download(simpleDirectoryListing[i], Globals.TEMPFOLDER + "temp.dio");
        ftpClient = null;
    }
コード例 #6
0
ファイル: Form1.cs プロジェクト: Jaesun0314/FTP
        //다운로드 버튼 ( '>' )
        private void btn_Download_Click(object sender, EventArgs e)
        {
            string  fileName      = string.Empty;
            string  localFullPath = string.Empty;
            FtpInfo info          = ReadFtpConfig();
            ftp     ftpClient     = new ftp(string.Format(@"ftp://{0}/{1}", info.host, info.remotePath), info.id, info.password);

            fileName = listBox_Remote.SelectedItem.ToString();
            info.lFiles.Add(fileName);
            localFullPath = string.Format(@"{0}{1}", txt_localpath.Text, fileName);

            ftpClient.download(fileName, localFullPath);

            //Local Directory List
            viewLocalListView(txt_localpath.Text);
        }
コード例 #7
0
        private void btnDownload_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;

            ftp ftpClientLocal = new ftp(StaticVarClass.ftp_Server, StaticVarClass.ftp_Username, StaticVarClass.ftp_Password);

            if (ftpClientLocal.download(str_EmployeeGlobal, ftpInfo.FileName, ftpInfo.FullName))
            {
                // Load lại attachFile.
                this.loadDataAttachFile();

                // Làm sạch control.
                this.clearDownload();
                this.disableAttachFileDownload(true);

                XtraMessageBox.Show("Successfully downloaded!", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                XtraMessageBox.Show("Download failed!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #8
0
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            mdlGlobal.loadXML();

            if (args != null &&
                args.Length > 1)
            {
                //MessageBox.Show(args[0]);
                // Global.MyBranchOffice = args[0];
                Global.CompanyCode = args[1];
                Global.intUserID   = Convert.ToInt32(args[2]);
                Application.Run(new frmMain());
            }
            else
            {
                //if (args.Length > 0 && args[0] == "-Update-")
                //{
                if (!File.Exists(Directory.GetCurrentDirectory() + @"\Updater.exe"))
                {
                    ApplicationUpdater(mdlGlobal.FtpRemoteHost, mdlGlobal.ftpUser, mdlGlobal.FtpPassword, "Updater.zip", "avUpd.xml");
                }

                ////Check Application Version
                //ApplicationUpdater(mdlGlobal.FtpRemoteHost, mdlGlobal.ftpUser, mdlGlobal.FtpPassword, "Version.txt", "");
                CultureInfo MyCultureInfo = new CultureInfo("en-US");
                ftp         ftpClient     = new ftp(@"ftp://" + mdlGlobal.FtpRemoteHost, mdlGlobal.ftpUser, mdlGlobal.FtpPassword);
                string      appPath       = Directory.GetCurrentDirectory() + @"\";
                ftpClient.download(mdlGlobal.ftpPath + "Version.txt", appPath + "Version.txt");
                if (ftpClient.error == null)
                {
                    try
                    {
                        Assembly assembly = Assembly.GetExecutingAssembly();
                        //MessageBox.Show(assembly.Location);
                        var    AppInfo        = FileVersionInfo.GetVersionInfo(assembly.Location);
                        string CompName       = AppInfo.CompanyName;
                        string CurrentVersion = AppInfo.ProductVersion.Trim();
                        var    u1             = new Version(CurrentVersion);
                        //MessageBox.Show(CurrectVersion);

                        string NewVersion = File.ReadAllText(appPath + "Version.txt");
                        var    u2         = new Version(NewVersion);
                        //MessageBox.Show(NewVersion);

                        if (u1.CompareTo(u2) < 0)
                        {
                            //    //update Updater.exe
                            //    //ApplicationUpdater(mdlGlobal.FtpRemoteHost, mdlGlobal.ftpUser, mdlGlobal.FtpPassword, "AVUpdater.zip", "av.xml");
                            //string message = "Aplikasi ini ada Versi terbarunya, apakah anda mau mengupgrade nya?";
                            //string title = AppInfo.ProductName + " - New Version";
                            //MessageBoxButtons buttons = MessageBoxButtons.YesNo;
                            //DialogResult result = MessageBox.Show(message, title, buttons);
                            //if (result == DialogResult.Yes)
                            frmUpdater frmUpdater = new frmUpdater(NewVersion, CurrentVersion, CompName);
                            frmUpdater.ShowDialog();
                            if (frmUpdater.Status == 1)
                            {
                                Application.Exit();
                                //MessageBox.Show("harusnya AllVision nya sudah exit dan mau buka updater");
                                //    //---------------------
                                try
                                {
                                    //try { foreach (Process proc in Process.GetProcessesByName("AllVision")) { proc.Kill(); } }
                                    //catch (Exception ex) {  MessageBox.Show(ex.Message);  }

                                    Process updater = new Process();
                                    updater.StartInfo.FileName  = Directory.GetCurrentDirectory() + @"\Updater.exe";
                                    updater.StartInfo.Arguments = "--FtpRemoteHost:" + mdlGlobal.FtpRemoteHost + " --FtpUser:"******" --FtpPassword:"******" AllVision Balimoon av";
                                    //updater.StartInfo.UseShellExecute = true;
                                    //updater.StartInfo.RedirectStandardOutput = true;
                                    updater.StartInfo.CreateNoWindow = false;
                                    updater.Start();
                                }
                                catch (Exception ex)
                                {
                                    MessageBox.Show(ex.Message, Global.strProductName);
                                }
                                //MessageBox.Show("Buka updater");
                            }
                            else
                            {
                                Application.Run(new frmLogin());
                            }
                        }
                        else
                        {
                            Application.Run(new frmLogin());
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, Global.strProductName);
                    }
                }
                else
                {
                    Application.Run(new frmLogin());
                }
            }
        }
コード例 #9
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;
        }
コード例 #10
0
ファイル: frmMDIParent.cs プロジェクト: checkup/check-up
        private void checkForUpdatesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string        downloadFullUrl = "";
            var           filenames       = new List <string>();
            Version       newVersion      = null;
            string        xmlUrl          = "http://jhunexjun.hostei.com/check-up/updates.xml";
            XmlTextReader reader          = null;

            try
            {
                reader = new XmlTextReader(xmlUrl);
                reader.MoveToContent();
                string elementName = ""; // the tag
                if ((reader.NodeType == XmlNodeType.Element) && reader.Name == "check-up")
                {
                    while (reader.Read())
                    {
                        if (reader.NodeType == XmlNodeType.Element)
                        {
                            elementName = reader.Name;
                        }
                        else
                        {
                            if ((reader.NodeType == XmlNodeType.Text) && (reader.HasValue))
                            {
                                switch (elementName)
                                {
                                case "version":
                                    newVersion = new Version(reader.Value);
                                    break;

                                case "downloadUrl":
                                    downloadFullUrl = reader.Value;
                                    break;

                                case "filename":
                                    filenames.Add(reader.Value);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }

            Version applicationVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;

            if (applicationVersion.CompareTo(newVersion) < 0)
            {
                DialogResult dr = MessageBox.Show(this, "Version " + newVersion.ToString() + " of Check-up is now available. Do you want to download it now?", "New version", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dr == DialogResult.Yes)
                {
                    Uri baseUri = new Uri(downloadFullUrl);
                    if (baseUri.Scheme != Uri.UriSchemeFtp)
                    {
                        MessageBox.Show(this, "Uri is not a valid format.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog();
                    folderBrowserDialog1.ShowDialog();

                    if (folderBrowserDialog1.SelectedPath != "")
                    {
                        Uri fullUri = null; Uri relativeUri = null;
                        int i = filenames.Count, c = 0;

                        foreach (string filename in filenames)
                        {
                            relativeUri = new Uri(filename, UriKind.Relative);
                            fullUri     = new Uri(baseUri, relativeUri);
                            ftp ftpDownload = new ftp("a2278315", "Systems33");

                            if (ftpDownload.download(fullUri.ToString(), folderBrowserDialog1.SelectedPath + @"\" + relativeUri.ToString()))
                            {
                                // let's not use this for now
                                //unInstallSoftware();

                                c++;
                            }
                        }

                        if (c == 0)
                        {
                            MessageBox.Show(this, "Nothing has been downloaded. Try downloading again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        else if (c > 0 && c == i)
                        {
                            MessageBox.Show(this, "All updates has been successfully downloaded.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else if (c > 0 && c < i)
                        {
                            MessageBox.Show(this, "One or more updates were not successully downloaded. Please download all.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }
                    else
                    {
                        MessageBox.Show(this, "No location has been selected. Downloading unsuccessful. Re-do the process if you want to download it.", "Download Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
            }
            else
            {
                MessageBox.Show(this, "This software is up-to-date.", "Message.", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
コード例 #11
0
	public void UIButton_Download(){

		ftp ftpClient = new ftp(@"ftp://140.131.152.3:7223/FTP/momoya", "momo6699", "123");
		//ftp ftpClient = new ftp(@"ftp://140.131.152.5:7223/Volume_1/momoya/", "momo6699", "123456");
		// 參數:  (ftp端 要存的檔案名稱,  本地端的路徑  note: 副檔名非常重要  jpg jpeg png 要分清楚)
		
		
		string str1 = usernameandpic[0] + ".png";
		string str2 = "/sdcard/" + usernameandpic[0] + ".png";
		
		//ftpClient.download(@"AR_test.jpg" , @str2);
		ftpClient.download(@str1 , @str2);
		
		DataManger.new_pic_path = img_path_prefix + str2;
		DataManger.b = true;
		
		checksent();
	}
コード例 #12
0
ファイル: sharedOP.cs プロジェクト: dromero88/FTPTools
    public void getFtpFile(string url, string user, string password, string file, string download_path)
    {
        ftp ftpClient = new ftp(url, user, password);

        ftpClient.download(file, download_path + "\\" + global.config.fichero);
    }