첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
0.00MB

▶ 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
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요