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); } }
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); }
//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; } }
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; } }