Exemple #1
0
        public static Stream FTPFileBinding(string qFTP_Path, string qFileName, string qFTP_ID, string qFTP_PW)  //추가
        {
            try
            {
                Stream responseStream = null;

                CoFAS_FTPUtilManager qFTPUtil = new CoFAS_FTPUtilManager(qFTP_Path, qFTP_ID, qFTP_PW);
                if (qFTPUtil.IsFTPFileExsit(qFTP_Path + qFileName))
                {
                    FtpWebRequest requestFileDownload = (FtpWebRequest)WebRequest.Create("ftp://" + qFTP_Path + qFileName);
                    requestFileDownload.Credentials = new NetworkCredential(qFTP_ID, qFTP_PW);
                    requestFileDownload.Method      = WebRequestMethods.Ftp.DownloadFile;

                    FtpWebResponse responseFileDownload = (FtpWebResponse)requestFileDownload.GetResponse();

                    return(responseStream = responseFileDownload.GetResponseStream());
                }
                else
                {
                    //CoFAS_DevExpressManager.ShowErrorMessage("FTP서버에 저장되지 않은 파일입니다. 저장을 먼저 해주세요.");
                    return(null);
                }
            }
            catch (Exception pException)
            {
                return(null);
            }
        }
Exemple #2
0
        public static bool FTPUpload_CheckDirectory(string pFileName, string qFullName, string qFTP_ID, string qFTP_PW, string qFTP_Path, string qDirectory)
        {
            bool IsUpload;

            try
            {
                // 파일존재확인
                CoFAS_FTPUtilManager qFTPUtil = new CoFAS_FTPUtilManager(qFTP_Path, qFTP_ID, qFTP_PW);
                if (!qFTPUtil.FtpDirectoryExists(qFTP_Path, qDirectory))    // qFTP_Path 디렉토리 체크해서     >> 여기서 해당 window_name의 폴더가 없다는 false를 내보냄.....
                {
                    //없으면 directory(qFTP_Path) 생성 단계 거쳐서 저장단계로 넘기기
                    qFTPUtil.MakeDirectory_AfterChecking(qFTP_Path + "/%2F/" + qDirectory);                            //  >> 그래서 여기서 해당 폴더를 만들려다가 에러를 내보내서, 폴더는 안 만들고
                }


                if (qFTPUtil.IsFTPFileExsit(qFTP_Path + "/%2F/" + qDirectory + "/%2F/" + pFileName))
                {
                    // 파일삭제하기
                    FtpWebRequest requestFileDelete = (FtpWebRequest)WebRequest.Create("ftp://" + qFTP_Path + "/%2F/" + qDirectory + "/" + pFileName);
                    requestFileDelete.Credentials = new NetworkCredential(qFTP_ID, qFTP_PW);
                    requestFileDelete.Method      = WebRequestMethods.Ftp.DeleteFile;

                    FtpWebResponse responseFileDelete = (FtpWebResponse)requestFileDelete.GetResponse();
                }

                FtpWebRequest requestFTPUploader = (FtpWebRequest)WebRequest.Create("ftp://" + qFTP_Path + "/%2F/" + qDirectory + "/" + pFileName);
                requestFTPUploader.Credentials = new NetworkCredential(qFTP_ID, qFTP_PW);
                requestFTPUploader.Method      = WebRequestMethods.Ftp.UploadFile;

                FileInfo   fileInfo   = new FileInfo(qFullName);
                FileStream fileStream = fileInfo.OpenRead();

                int    bufferLength = 102400;
                byte[] buffer       = new byte[bufferLength];

                Stream uploadStream  = requestFTPUploader.GetRequestStream();
                int    contentLength = fileStream.Read(buffer, 0, bufferLength);

                while (contentLength != 0)
                {
                    uploadStream.Write(buffer, 0, contentLength);
                    contentLength = fileStream.Read(buffer, 0, bufferLength);
                }

                uploadStream.Close();
                fileStream.Close();

                requestFTPUploader = null;

                IsUpload = true;
            }
            catch (Exception pException)
            {
                IsUpload = false;
            }
            return(IsUpload);
        }
Exemple #3
0
        public static bool FTPUpload_DataofByte_CheckDirectory_Encoding(string pFileName, string qFTP_ID, string qFTP_PW, string qFTP_Path, string qDirectory, byte[] qFileData, string qLOCAL_PATH)
        {
            bool   IsUpload;
            Stream reqStream;

            try
            {
                CoFAS_FTPUtilManager qFTPUtil = new CoFAS_FTPUtilManager(qFTP_Path, qFTP_ID, qFTP_PW);
                if (!qFTPUtil.FtpDirectoryExists(qFTP_Path, qDirectory))    // qFTP_Path 디렉토리 체크해서     >> 여기서 해당 window_name의 폴더가 없다는 false를 내보냄.....
                {
                    //없으면 directory(qFTP_Path) 생성 단계 거쳐서 저장단계로 넘기기
                    qFTPUtil.MakeDirectory_AfterChecking(qFTP_Path + "/%2F/" + qDirectory);
                }

                //해당 파일이 있는지 없는지 확인하는 부분
                // >> 있으면 삭제, 없으면 업로드

                FtpWebRequest requestFTPUploader = (FtpWebRequest)WebRequest.Create("ftp://" + qFTP_Path + "/%2F/" + qDirectory + "/" + pFileName);
                requestFTPUploader.Credentials = new NetworkCredential(qFTP_ID, qFTP_PW);
                requestFTPUploader.Method      = WebRequestMethods.Ftp.UploadFile;

                byte[] data = new byte[qFileData.Length]; // qFileData;

                requestFTPUploader.ContentLength = data.Length;

                using (StreamReader sourceStream = new StreamReader(qLOCAL_PATH))
                {
                    data = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
                }

                using (reqStream = requestFTPUploader.GetRequestStream())
                {
                    reqStream.Write(data, 0, data.Length);
                }
                if (reqStream != null)
                {
                    reqStream.Close();
                }

                IsUpload = true;
            }
            catch (Exception pException)
            {
                IsUpload = false;
            }

            return(IsUpload);
        }
Exemple #4
0
        //public static void FTPUpload(string pFileName, string qPath, string qFullName, string qFTP_ID, string qFTP_PW, string qFTP_Path)
        public static void FTPUpload(string pFileName, string qFullName, string qFTP_ID, string qFTP_PW, string qFTP_Path)
        {
            try
            {
                // 파일존재확인
                CoFAS_FTPUtilManager qFTPUtil = new CoFAS_FTPUtilManager(qFTP_Path, qFTP_ID, qFTP_PW);
                if (qFTPUtil.IsFTPFileExsit(qFTP_Path + pFileName))
                {
                    // 파일삭제하기
                    FtpWebRequest requestFileDelete = (FtpWebRequest)WebRequest.Create("ftp://" + qFTP_Path + pFileName);
                    requestFileDelete.Credentials = new NetworkCredential(qFTP_ID, qFTP_PW);
                    requestFileDelete.Method      = WebRequestMethods.Ftp.DeleteFile;

                    FtpWebResponse responseFileDelete = (FtpWebResponse)requestFileDelete.GetResponse();
                }

                FtpWebRequest requestFTPUploader = (FtpWebRequest)WebRequest.Create("ftp://" + qFTP_Path + pFileName);
                requestFTPUploader.Credentials = new NetworkCredential(qFTP_ID, qFTP_PW);
                requestFTPUploader.Method      = WebRequestMethods.Ftp.UploadFile;

                FileInfo   fileInfo   = new FileInfo(qFullName);
                FileStream fileStream = fileInfo.OpenRead();

                int    bufferLength = 102400;
                byte[] buffer       = new byte[bufferLength];

                Stream uploadStream  = requestFTPUploader.GetRequestStream();
                int    contentLength = fileStream.Read(buffer, 0, bufferLength);

                while (contentLength != 0)
                {
                    uploadStream.Write(buffer, 0, contentLength);
                    contentLength = fileStream.Read(buffer, 0, bufferLength);
                }

                uploadStream.Close();
                fileStream.Close();

                requestFTPUploader = null;
            }
            catch (Exception pException)
            {
                return;
            }
        }
Exemple #5
0
        public static void FTPUpload_CheckDFile(string pFileName, string qFTP_ID, string qFTP_PW, string qFTP_Path, byte[] qFileData)
        {
            try
            {
                CoFAS_FTPUtilManager qFTPUtil = new CoFAS_FTPUtilManager(qFTP_Path, qFTP_ID, qFTP_PW);
                if (qFTPUtil.IsFTPFileExsit(qFTP_Path + pFileName))
                {
                    // 파일삭제하기
                    FtpWebRequest requestFileDelete = (FtpWebRequest)WebRequest.Create("ftp://" + qFTP_Path + pFileName);
                    requestFileDelete.Credentials = new NetworkCredential(qFTP_ID, qFTP_PW);
                    requestFileDelete.Method      = WebRequestMethods.Ftp.DeleteFile;

                    FtpWebResponse responseFileDelete = (FtpWebResponse)requestFileDelete.GetResponse();
                }
                FtpWebRequest requestFTPUploader = (FtpWebRequest)WebRequest.Create("ftp://" + qFTP_Path + "/%2F/" + pFileName);
                requestFTPUploader.Credentials = new NetworkCredential(qFTP_ID, qFTP_PW);
                requestFTPUploader.Method      = WebRequestMethods.Ftp.UploadFile;

                byte[] data = qFileData;

                requestFTPUploader.ContentLength = data.Length;
                using (Stream reqStream = requestFTPUploader.GetRequestStream())
                {
                    reqStream.Write(data, 0, data.Length);
                }

                using (FtpWebResponse resp = (FtpWebResponse)requestFTPUploader.GetResponse())
                {
                    Console.WriteLine("Upload: {0}", resp.StatusDescription);
                }
            }
            catch (Exception pException)
            {
                return;
            }
        }
Exemple #6
0
        public static bool FTPUpload_DataofStream_CheckDirectory(string pFileName, string qFTP_ID, string qFTP_PW, string qFTP_Path, string qDirectory, byte[] qFileData, string qLOCAL_PATH)
        {
            bool   IsUpload;
            Stream reqStream;

            //읽을 화일 경로 및 이름 설정
            FileInfo fileinf = new FileInfo(qLOCAL_PATH);
            //파일 오픈 파일 스트림 상태로 읽어들임
            FileStream fs = fileinf.OpenRead();

            try
            {
                //FTP 오픈
                CoFAS_FTPUtilManager qFTPUtil = new CoFAS_FTPUtilManager(qFTP_Path, qFTP_ID, qFTP_PW);
                //ftp 폴더에 디렉토리가 없으면 생성
                if (!qFTPUtil.FtpDirectoryExists(qFTP_Path, qDirectory))    // qFTP_Path 디렉토리 체크해서     >> 여기서 해당 window_name의 폴더가 없다는 false를 내보냄.....
                {
                    //없으면 directory(qFTP_Path) 생성 단계 거쳐서 저장단계로 넘기기
                    qFTPUtil.MakeDirectory_AfterChecking(qFTP_Path + "/%2F/" + qDirectory);
                }

                //해당 파일이 있는지 없는지 확인하는 부분
                // >> 있으면 삭제, 없으면 업로드

                FtpWebRequest requestFTPUploader = (FtpWebRequest)WebRequest.Create("ftp://" + qFTP_Path + "/%2F/" + qDirectory + "/" + pFileName);
                requestFTPUploader.Credentials = new NetworkCredential(qFTP_ID, qFTP_PW);
                requestFTPUploader.Method      = WebRequestMethods.Ftp.UploadFile;

                byte[] data = qFileData;

                requestFTPUploader.ContentLength = data.Length;

                int contentLen;

                using (reqStream = requestFTPUploader.GetRequestStream())
                {
                    contentLen = fs.Read(data, 0, data.Length);

                    while (contentLen != 0)
                    {
                        reqStream.Write(data, 0, contentLen);
                        contentLen = fs.Read(data, 0, data.Length);
                    }

                    //reqStream.Write(data, 0, data.Length);
                }
                if (reqStream != null)
                {
                    reqStream.Close();
                    fs.Close();
                }

                IsUpload = true;
            }
            catch (Exception pException)
            {
                IsUpload = false;
            }

            return(IsUpload);
        }