예제 #1
0
        public static void UploadFileTest(MainForm frm)
        {
            PFWinFTP  ftp = new PFWinFTP();
            Stopwatch sw  = new Stopwatch();

            try
            {
                sw.Start();

                _msg.Length = 0;
                _msg.Append("UploadFileTest started ...\r\n");
                Program._messageLog.WriteLine(_msg.ToString());

                InitializeFtpFromForm(frm, ftp);

                //_msg.Length = 0;
                //_msg.Append("_ftp object:\r\n");
                //_msg.Append(_ftp.ToString());
                //Program._messageLog.WriteLine(_msg.ToString());

                ftp.UploadFileToFtpHost();

                if (ftp.RemoteFileExists(frm.txtRemoteFile.Text))
                {
                    _msg.Length = 0;
                    _msg.Append(frm.txtRemoteFile.Text);
                    _msg.Append(" was written to ");
                    _msg.Append(ftp.FtpHost);
                }
                else
                {
                    _msg.Length = 0;
                    _msg.Append("Unable to find ");
                    _msg.Append(frm.txtRemoteFile.Text);
                    _msg.Append(" on ");
                    _msg.Append(ftp.FtpHost);
                }
                Program._messageLog.WriteLine(_msg.ToString());
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                Program._messageLog.WriteLine(_msg.ToString());
                AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }
            finally
            {
                sw.Stop();
                _msg.Length = 0;
                _msg.Append("\r\nElapsed time: ");
                _msg.Append(sw.FormattedElapsedTime);
                Program._messageLog.WriteLine(_msg.ToString());

                _msg.Length = 0;
                _msg.Append("\r\n... UploadFileTest finished.");
                Program._messageLog.WriteLine(_msg.ToString());
            }
        }
예제 #2
0
 private static void InitializeFtpFromForm(MainForm frm, PFWinFTP ftp)
 {
     ftp.FtpHost     = frm.txtFtpHost.Text;
     ftp.FtpUsername = frm.txtFtpUsername.Text;
     ftp.FtpPassword = frm.txtFtpPassword.Text;
     //ftp.UseAsyncFileTransfer = frm.chkUseAsync.Checked;
     //ftp.ProgressIntervalInSeconds = AppTextGlobals.ConvertStringToInt(frm.txtProgressIntervalInSecs.Text, 1);
     //ftp.RetryTimeout = AppTextGlobals.ConvertStringToInt(frm.txtRetryTimeout.Text, 300000);
     //ftp.UseFipsCompliantMode = frm._useFipsCompliantMode;
     ftp.FtpBufferSize        = AppTextGlobals.ConvertStringToInt(frm.txtBufferSize.Text, 32767);
     ftp.SourceFile           = frm.txtLocalSourceFile.Text;
     ftp.RemoteFile           = frm.txtRemoteFile.Text;
     ftp.LocalDestinationFile = frm.txtLocalDestinationFile.Text;
 }
예제 #3
0
        public static void ListRemoteFolderFilesTest(MainForm frm)
        {
            PFWinFTP  ftp = new PFWinFTP();
            Stopwatch sw  = new Stopwatch();

            try
            {
                sw.Start();

                _msg.Length = 0;
                _msg.Append("ListRemoteFolderFilesTest started ...\r\n");
                Program._messageLog.WriteLine(_msg.ToString());

                InitializeFtpFromForm(frm, ftp);

                string        folderName = Path.GetDirectoryName(frm.txtRemoteFile.Text).Replace(@"\", @"/");
                List <string> files      = ftp.ListRemoteDirectoryFiles(folderName);

                foreach (string fi in files)
                {
                    _msg.Length = 0;
                    _msg.Append("FileName: ");
                    _msg.Append(fi);
                    _msg.Append("\r\n");
                    Program._messageLog.WriteLine(_msg.ToString());
                }
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                Program._messageLog.WriteLine(_msg.ToString());
                AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }
            finally
            {
                sw.Stop();
                _msg.Length = 0;
                _msg.Append("\r\nElapsed time: ");
                _msg.Append(sw.FormattedElapsedTime);
                Program._messageLog.WriteLine(_msg.ToString());

                _msg.Length = 0;
                _msg.Append("\r\n... ListRemoteFolderFilesTest finished.");
                Program._messageLog.WriteLine(_msg.ToString());
            }
        }
예제 #4
0
        public static void DeleteRemoteFileTest(MainForm frm)
        {
            PFWinFTP  ftp = new PFWinFTP();
            Stopwatch sw  = new Stopwatch();

            try
            {
                sw.Start();

                _msg.Length = 0;
                _msg.Append("DeleteRemoteFileTest started ...\r\n");
                Program._messageLog.WriteLine(_msg.ToString());

                InitializeFtpFromForm(frm, ftp);

                if (ftp.RemoteFileExists(frm.txtRemoteFile.Text))
                {
                    _msg.Length = 0;
                    _msg.Append(frm.txtRemoteFile.Text);
                    _msg.Append(" exists on ");
                    _msg.Append(ftp.FtpHost);
                    Program._messageLog.WriteLine(_msg.ToString());
                }
                else
                {
                    _msg.Length = 0;
                    _msg.Append("Unable to find ");
                    _msg.Append(frm.txtRemoteFile.Text);
                    _msg.Append(" on ");
                    _msg.Append(ftp.FtpHost);
                    throw new FileNotFoundException(_msg.ToString());
                }

                bool deleteSucceeded = ftp.DeleteRemoteFile(frm.txtRemoteFile.Text);

                if (deleteSucceeded)
                {
                    Program._messageLog.WriteLine("Delete succeeded.");
                }
                else
                {
                    Program._messageLog.WriteLine("Delete failed.");
                }

                if (ftp.RemoteFileExists(frm.txtRemoteFile.Text))
                {
                    _msg.Length = 0;
                    _msg.Append(frm.txtRemoteFile.Text);
                    _msg.Append(" exists on ");
                    _msg.Append(ftp.FtpHost);
                    Program._messageLog.WriteLine(_msg.ToString());
                }
                else
                {
                    _msg.Length = 0;
                    _msg.Append("Unable to find ");
                    _msg.Append(frm.txtRemoteFile.Text);
                    _msg.Append(" on ");
                    _msg.Append(ftp.FtpHost);
                    Program._messageLog.WriteLine(_msg.ToString());
                }
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                Program._messageLog.WriteLine(_msg.ToString());
                AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }
            finally
            {
                sw.Stop();
                _msg.Length = 0;
                _msg.Append("\r\nElapsed time: ");
                _msg.Append(sw.FormattedElapsedTime);
                Program._messageLog.WriteLine(_msg.ToString());

                _msg.Length = 0;
                _msg.Append("\r\n... DeleteRemoteFileTest finished.");
                Program._messageLog.WriteLine(_msg.ToString());
            }
        }