예제 #1
0
 private void WriteLog(LogTypes LogType, CAfterFileUploadEventArgs e)
 {
     WriteLog(LogType, e.LocalFullPath, e.LocalFullPathNew, e.RemoteFullUrl, null);
 }
예제 #2
0
 private void ftp_AfterFileUpload(object sender, CAfterFileUploadEventArgs e)
 {
     this.mCountSucceeded++;
     WriteLog(LogTypes.Copy, e);
 }
예제 #3
0
파일: CFtp2.cs 프로젝트: doctorgu/MadeIn9
        /// <summary>
        /// FTP 서버에 클라이언트 컴퓨터의 파일을 업로드함.
        /// </summary>
        /// <param name="LocalFullPath">클라이언트 컴퓨터의 파일 전체 경로</param>
        /// <param name="RemoteFolder">서버의 폴더 위치</param>
        /// <param name="RemoteFile">서버의 파일 이름</param>
        public void UploadFile(string LocalFullPath, string RemoteFolder, string RemoteFile)
        {
            string LocalFullPathNew = "";

            if (this.BeforeFileUpload != null)
            {
                CBeforeFileUploadEventArgs e = new CBeforeFileUploadEventArgs()
                {
                    LocalFullPath = LocalFullPath
                };
                this.BeforeFileUpload(this, e);

                if (e.Cancel)
                {
                    return;
                }

                if (!string.IsNullOrEmpty(e.LocalFullPathNew))
                {
                    LocalFullPathNew = e.LocalFullPathNew;
                }
            }

            try
            {
                Uri RemoteUri = GetRemoteUri(RemoteFolder, RemoteFile);

                FtpWebRequest FtpReq = (FtpWebRequest)WebRequest.Create(RemoteUri);
                if (!string.IsNullOrEmpty(this._Info.UserId))
                {
                    FtpReq.Credentials = new NetworkCredential(this._Info.UserId, this._Info.Password);
                }
                FtpReq.UsePassive = this._Info.UsePassive;

                FtpReq.Method = WebRequestMethods.Ftp.UploadFile;

                using (FileStream readStream = new FileStream((!string.IsNullOrEmpty(LocalFullPathNew) ? LocalFullPathNew : LocalFullPath), FileMode.Open, FileAccess.Read))
                {
                    using (Stream writeStream = FtpReq.GetRequestStream())
                    {
                        int    Length    = 256;
                        Byte[] buffer    = new Byte[Length];
                        int    bytesRead = readStream.Read(buffer, 0, Length);

                        while (bytesRead > 0)
                        {
                            writeStream.Write(buffer, 0, bytesRead);
                            bytesRead = readStream.Read(buffer, 0, Length);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (this.FileUploadFailed != null)
                {
                    CFileUploadFailedEventArgs e = new CFileUploadFailedEventArgs()
                    {
                        LocalFullPath    = LocalFullPath,
                        LocalFullPathNew = LocalFullPathNew,
                        RemoteFullUrl    = CPath.CombineUrl(RemoteFolder, RemoteFile),
                        ex = ex
                    };
                    this.FileUploadFailed(this, e);
                    return;
                }
                else
                {
                    throw new Exception(ex.Message, ex);
                }
            }

            if (this.AfterFileUpload != null)
            {
                CAfterFileUploadEventArgs e = new CAfterFileUploadEventArgs()
                {
                    LocalFullPath    = LocalFullPath,
                    LocalFullPathNew = LocalFullPathNew,
                    RemoteFullUrl    = CPath.CombineUrl(RemoteFolder, RemoteFile)
                };
                this.AfterFileUpload(this, e);
            }
        }