Exemplo n.º 1
0
        /// <summary>
        /// Uploading a File to FTP Server
        /// </summary>
        /// <param name="UploadFilePath">Path of the File on Local File System. ex: c:\Users\FileName.txt</param>
        /// <param name="UploadDirectory">Upload Directory on the Remote FTP Server</param>
        /// <param name="FtpClient">FTP Client We will be using</param>
        public frmUpload(string UploadFilePath, string UploadDirectory, FTPclient Ftpclient)
        {
            InitializeComponent();

            //Setup Variables
            FileName                = System.IO.Path.GetFileName(UploadFilePath);      //FileName without Directory. ex: FileName.txt
            lblFileName.Text        = Ftpclient.Hostname + UploadDirectory + FileName; //lblFileName displays full Upload Path.
            lblUploadDirectory.Text = UploadDirectory;                                 //Upload Directory
            FtpClient               = Ftpclient;

            //Aero Composition Event
            AeroGlassCompositionChanged += new AeroGlassCompositionChangedEvent(frmUpload_AeroGlassCompositionChanged);

            if (AeroGlassCompositionEnabled)
            {
                //We don't want pnlNonTransparent and the controls in it to be part of AERO
                //but we do want Aero...looks cool ;)
                ExcludeControlFromAeroGlass(pnlNonTransparent);
            }
            else
            {
                this.BackColor = Color.Teal;
            }

            //Show Form
            this.Show();

            //Setup our Download Client and Start Downloading
            FtpClient.CurrentDirectory         = UploadDirectory;
            FtpClient.OnUploadCompleted       += new FTPclient.UploadCompletedHandler(FtpClient_OnUploadCompleted);
            FtpClient.OnUploadProgressChanged += new FTPclient.UploadProgressChangedHandler(FtpClient_OnUploadProgressChanged);
            FtpClient.Upload(UploadFilePath, UploadDirectory + FileName);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Uploads all files within the specified directory.
        /// </summary>
        /// <param name="directoryPath">All files within this directory will be uploaded to the FTP server.</param>
        public void UploadLogs(string directoryPath)
        {
            if (_isVerbose)
                Console.WriteLine("*** UPLOADING DAILY LOG FILES ({0}) ***", DateTime.Now);

            FTPclient ftp = new FTPclient(_ftpHost, _ftpUser, _ftpPass);
            //string individualLogDirecotry = Path.Combine(LogDirectory, "individual");

            foreach (string logFile in Directory.GetFiles(directoryPath))
            {
                if (_isVerbose)
                    Console.Write(" - Uploading {0}... ", logFile);

                if (ftp.Upload(Path.GetFullPath(logFile), String.Format("{0:yyyy-MM-dd_hh-mm-ss-tt}-{1}", DateTime.Now, Path.GetFileName(logFile))))
                {
                    File.Delete(logFile);

                    if (_isVerbose)
                        Console.WriteLine("done!");
                }
            }

            if (_isVerbose)
                Console.WriteLine("*** UPLOAD COMPLETE ***");
        }
Exemplo n.º 3
0
        void tFtp_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            ConfigHandler conf = ConfigHandler.instance;
            FTPclient     ftp  = new FTPclient(conf.ftpHost, conf.ftpUserName, conf.ftpUserPassword);
            DirectoryInfo di   = new DirectoryInfo(ConfigHandler.instance.tempfolder);

            foreach (FileInfo f in di.GetFiles())
            {
                if (f.Length > ConfigHandler.instance.maximmiumValue)
                {
                    string fileName = String.Concat(ftp.CurrentDirectory, "/", f.Name);
                    bool   res      = ftp.Upload(f, fileName);
                    if (res)
                    {
                        f.Delete();
                    }
                }
            }
            string stmtFullPath = String.Concat(ftp.CurrentDirectory, conf.stmtFile);

            if (ftp.FtpFileExists(stmtFullPath))
            {
                string downPath = Path.Combine(conf.tempfolder, conf.stmtFile);
                ftp.Download(stmtFullPath, downPath, true);
                ftp.FtpDelete(stmtFullPath);
                //Bussiness Method
                ProcessStmtFile(downPath);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Uploads the specified file to the FTP server.
        /// </summary>
        /// <param name="localFilename">The filename of the log file you wish to upload.</param>
        /// <param name="remoteFilename">The filename that you wish to save the log file with on the FTP server.</param>
        public void UploadLog(string localFilename, string remoteFilename)
        {
            while (true)
            {
                if (!File.Exists(localFilename))
                    return;

                if (_isVerbose)
                    Console.WriteLine("*** UPLOADING OVERALL LOG FILE ***");

                FTPclient ftp = new FTPclient(_ftpHost, _ftpUser, _ftpPass);

                //if (ftp.Upload(Path.GetFullPath(OverallLog), String.Format("{0:yyyy-MM-dd_hh-mm-ss-tt}.log", DateTime.Now)))
                if (ftp.Upload(Path.GetFullPath(localFilename), String.Format("{0}.log", remoteFilename)))
                {
                    if (_isVerbose)
                        Console.WriteLine("*** UPLOAD SUCCESSFUL ***");
                }
                else
                {
                    if (_isVerbose)
                        Console.WriteLine("*** UPLOAD FAILED - RETRYING ***");

                    continue;
                }
                break;
            }
        }
Exemplo n.º 5
0
        public bool Upload(Uri host, string localFilename)
        {
            string targFileName = Path.GetFileName(localFilename);

            FTPclient ftp = new FTPclient(host.AbsoluteUri, FtpUser, FtpPassword);

            ftp.UsePassive = true;

            return(ftp.Upload(localFilename, targFileName));
        }