Overview :
메인 소스
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
using System.Diagnostics; :: 중략 :: private void WinSCP() { string batDir = @"C:\SCP\"; string batFile = "MyScript.bat"; Process proc = null; try { if (batDir.Length > 2 && batFile.Length > 2) { proc = new Process(); proc.StartInfo.WorkingDirectory = batDir; proc.StartInfo.FileName = batFile; proc.StartInfo.CreateNoWindow = false; proc.Start(); proc.WaitForExit(); //LogShow("파일전송 스크립트가 실행 되었습니다."); } } catch (Exception ex) { //LogShow(ex.StackTrace.ToString()); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
using System; using System.Windows.Forms; using System.Threading; using System.Diagnostics; namespace WinFTPProcess { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnStart_Click(object sender, EventArgs e) { int sTime = 1000000; switch (cmbTime.SelectedIndex) { case 0: sTime = 5 * 1000; //5초 break; case 1: sTime = 30 * 1000; //30초 break; case 2: sTime = 10 * 60 * 1000; //10분 break; default: sTime = 20 * 60 * 1000; //20분 break; } if (txtBatFile.Text.Length > 5) { timer2.Interval = 2000; timer2.Enabled = true; timer2.Start(); timer1.Interval = sTime; timer1.Enabled = true; timer1.Start(); btnStart.Enabled = false; btnStop.Enabled = true; LogShow("FTP 를 시작 합니다."); WinSCP(); //WinSCP를 시작합니다. } } private void Form1_Load(object sender, EventArgs e) { //Start Stop 버튼 init btnStart.Enabled = true; btnStop.Enabled = false; // Timer init timer1.Enabled = false; // cmbTime init cmbTime.SelectedIndex = 1; //timer2 int timer2.Enabled = false; timer2.Interval = 2000; } private void btnStop_Click(object sender, EventArgs e) { //stop 버튼을 누르면 btnStart.Enabled = true; btnStop.Enabled = false; LogShow("중지 되었습니다."); timer2.Stop(); timer2.Enabled = false; timer1.Stop(); timer1.Enabled = false; toolStripProgressBar1.Value = 0; } //FTP WinSCP private void WinSCP() { string batDir = txtBatDir.Text; string batFile = txtBatFile.Text; Process proc = null; try { if (batDir.Length > 2 && batFile.Length > 2) { proc = new Process(); proc.StartInfo.WorkingDirectory = batDir; proc.StartInfo.FileName = batFile; proc.StartInfo.CreateNoWindow = false; proc.Start(); proc.WaitForExit(); LogShow("파일전송 스크립트가 실행 되었습니다."); } } catch (Exception ex) { LogShow(ex.StackTrace.ToString()); } } //로그 뿌려주기 함수 private void LogShow(string LogDate) { if (txtLog.Text.Length > 1000) txtLog.Text = DateTime.Now.ToString() + " " + LogDate; else txtLog.Text = txtLog.Text + "\r\n" + DateTime.Now.ToString() + " " + LogDate; txtLog.SelectionStart = txtLog.Text.Length; txtLog.ScrollToCaret(); txtLog.Refresh(); } private void timer1_Tick(object sender, EventArgs e) { WinSCP(); //파일전송 } private void timer2_Tick(object sender, EventArgs e) { toolStripProgressBar1.Value = 0; Thread.Sleep(1000); toolStripProgressBar1.Value = 100; } } } |