[C#/COMMON] WebClient 클래스 : UploadFile 메소드를 사용해 넥서스 저장소(Nexus Repository)에 파일 업로드하기
C#/Common 2021. 3. 10. 20:59728x90
반응형
728x170
▶ NexusHelper.cs
using System.Net;
namespace TestProject
{
/// <summary>
/// 넥서스 헬퍼
/// </summary>
public static class NexusHelper
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Property
////////////////////////////////////////////////////////////////////////////////////////// Static
//////////////////////////////////////////////////////////////////////////////// Public
#region 사용자 ID - UserID
/// <summary>
/// 사용자 ID
/// </summary>
public static string UserID { get; set; }
#endregion
#region 패스워드 - Password
/// <summary>
/// 패스워드
/// </summary>
public static string Password { get; set; }
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Static
//////////////////////////////////////////////////////////////////////////////// Public
#region 파일 업로드 하기 - UploadFile(sourceFilePath, targetURI)
/// <summary>
/// 파일 업로드 하기
/// </summary>
/// <param name="sourceFilePath">소스 파일 경로</param>
/// <param name="targetURI">타겟 URI</param>
public static void UploadFile(string sourceFilePath, string targetURI)
{
using(WebClient client = new WebClient())
{
client.Credentials = new NetworkCredential(UserID, Password);
client.UploadFile(targetURI, "PUT", sourceFilePath);
}
}
#endregion
#region 파일 삭제하기 - DeleteFile(targetURI)
/// <summary>
/// 파일 삭제하기
/// </summary>
/// <param name="targetURI">타겟 URI</param>
public static void DeleteFile(string targetURI)
{
using(WebClient client = new WebClient())
{
client.Credentials = new NetworkCredential(UserID, Password);
client.UploadData(targetURI, "DELETE", new byte[] { 1 });
}
}
#endregion
}
}
728x90
▶ Program.cs
namespace TestProject
{
/// <summary>
/// 프로그램
/// </summary>
class Program
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Static
//////////////////////////////////////////////////////////////////////////////// Private
#region 프로그램 시작하기 - Main()
/// <summary>
/// 프로그램 시작하기
/// </summary>
private static void Main()
{
NexusHelper.UserID = "userid";
NexusHelper.Password = "password";
string sourceFilePath = "d:\\test.txt";
string targetURI = "http://127.0.0.1/repository/arca/download/test.txt";
// 파일을 업로드한다.
NexusHelper.UploadFile(sourceFilePath, targetURI);
// 파일을 삭제한다.
NexusHelper.DeleteFile(targetURI);
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > Common' 카테고리의 다른 글
[C#/COMMON] 한글 윈도우즈 10에서 계산기 UWP 앱 윈도우 최소화하기 (0) | 2021.04.02 |
---|---|
[C#/COMMON] 프로세스 ID를 사용해 윈도우 핸들 리스트 구하기 (0) | 2021.04.02 |
[C#/COMMON] 누겟 설치 : InputSimulator (0) | 2021.03.27 |
[C#/COMMON] ZipArchive 클래스 : ZIP 파일 생성하기/추출하기 (기능 개선) (0) | 2021.03.27 |
[C#/COMMON] NetworkInterface 클래스 : GetAllNetworkInterfaces 정적 메소드를 사용해 VPN 네트워크 인터페이스 리스트 구하기 (0) | 2021.03.23 |
[C#/COMMON] 정적 로컬 함수(Static Local Function) 사용하기 (0) | 2021.03.09 |
[C#/COMMON] 구조체 읽기 전용 멤버 사용하기 (0) | 2021.03.09 |
[C#/COMMON] 널 병합 할당 연산자 ??= (Null Coalescing Assignment Oparator) 사용하기 (0) | 2021.03.09 |
[C#/COMMON] 실행 취소하기 (0) | 2021.03.07 |
[C#/COMMON] 누겟 설치 : Meshellator (0) | 2021.03.06 |
댓글을 달아 주세요