728x90
반응형
728x170
▶ MainForm.cs
using System;
using System.Drawing;
using System.IO;
using System.Net;
using System.Windows.Forms;
namespace TestProject
{
/// <summary>
/// 메인 폼
/// </summary>
public partial class MainForm : Form
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainForm()
/// <summary>
/// 생성자
/// </summary>
public MainForm()
{
InitializeComponent();
#region 이벤트를 설정한다.
Load += Form_Load;
this.fileButton.Click += fileButton_Click;
this.uploadButton.Click += uploadButton_Click;
#endregion
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
//////////////////////////////////////////////////////////////////////////////// Event
#region 폼 로드시 처리하기 - Form_Load(sender, e)
/// <summary>
/// 폼 로드시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void Form_Load(object sender, EventArgs e)
{
this.fileButton.Image = Image.FromFile("ellipsis.png");
this.fileTextBox.Text = Application.ExecutablePath;
}
#endregion
#region 파일 버튼 클릭시 처리하기 - fileButton_Click(sender, e)
/// <summary>
/// 파일 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void fileButton_Click(object sender, EventArgs e)
{
if(this.openFileDialog.ShowDialog() == DialogResult.OK)
{
this.fileTextBox.Text = this.openFileDialog.FileName;
}
}
#endregion
#region 업로드 버튼 클릭시 처리하기 - uploadButton_Click(sender, e)
/// <summary>
/// 업로드 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void uploadButton_Click(object sender, EventArgs e)
{
try
{
Cursor = Cursors.WaitCursor;
this.statusLabel.Text = "작업을 시작합니다.";
Application.DoEvents();
UploadFile
(
this.fileTextBox.Text,
this.urlTextBox.Text,
this.userNameTextBox.Text,
this.passwordTextBox.Text
);
this.statusLabel.Text = "작업을 완료했습니다.";
}
catch(Exception exception)
{
this.statusLabel.Text = "에러가 발생했습니다.";
MessageBox.Show(exception.Message);
}
finally
{
Cursor = Cursors.Default;
}
}
#endregion
//////////////////////////////////////////////////////////////////////////////// Function
#region 파일 업로드 하기 - private void UploadFile(filePath, ftpURL, ftpUserName, ftpPassword)
/// <summary>
/// 파일 업로드 하기
/// </summary>
/// <param name="filePath">파일 경로</param>
/// <param name="ftpURL">FTP URL</param>
/// <param name="ftpUserName">FTP 사용자명</param>
/// <param name="ftpPassword">FTP 패스워드</param>
private void UploadFile(string filePath, string ftpURL, string ftpUserName, string ftpPassword)
{
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpURL);
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential(ftpUserName, ftpPassword);
byte[] byteArray = File.ReadAllBytes(filePath);
request.ContentLength = byteArray.Length;
using(Stream stream = request.GetRequestStream())
{
stream.Write(byteArray, 0, byteArray.Length);
stream.Close();
}
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > Common' 카테고리의 다른 글
[C#/COMMON] 프로세서 수 구하기 (0) | 2018.12.24 |
---|---|
[C#/COMMON] 분할 문제 해결을 위한 분기와 초기 휴리스틱 바인딩 사용하기 (0) | 2018.12.24 |
[C#/COMMON] 분할 문제 해결을 위한 분기와 바인딩 사용하기 (0) | 2018.12.24 |
[C#/COMMON] 분할 문제 해결을 위한 소모적 탐색 사용하기 (0) | 2018.12.24 |
[C#/COMMON] FTP 파일 크기 및 시간 구하기 (0) | 2018.12.23 |
[C#/COMMON] FTP 텍스트 업로드 하기 (0) | 2018.12.23 |
[C#/COMMON] 실행시 로케일(Locale) 변경하기 (0) | 2018.12.23 |
[C#/COMMON] n번째 루트 계산하기 (0) | 2018.12.23 |
[C#/COMMON] 방화벽 상태 구하기 (0) | 2018.12.23 |
[C#/COMMON] 특수 기호 표시하기 (0) | 2018.12.23 |
댓글을 달아 주세요