1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | private bool FtpGetFile() { bool rtnFlag = false; try { if (!System.IO.Directory.Exists(tempPath)) { System.IO.Directory.CreateDirectory(tempPath); } Uri sourceFileUri = new Uri(ftpUri + programName); FtpWebRequest ftpWebRequest = WebRequest.Create(sourceFileUri) as FtpWebRequest; ftpWebRequest.UsePassive = false; ftpWebRequest.Credentials = new NetworkCredential(userID, userPW); ftpWebRequest.Method = WebRequestMethods.Ftp.DownloadFile; FtpWebResponse ftpWebResponse = ftpWebRequest.GetResponse() as FtpWebResponse; Stream sourceStream = ftpWebResponse.GetResponseStream(); FileStream targetFileStream = new FileStream(tempPath + @"\" + programName, FileMode.Create, FileAccess.Write); byte[] bufferByteArray = new byte[1024]; while (true) { int byteCount = sourceStream.Read(bufferByteArray, 0, bufferByteArray.Length); if (byteCount == 0) { break; } targetFileStream.Write(bufferByteArray, 0, byteCount); } targetFileStream.Close(); sourceStream.Close(); rtnFlag = true; } catch (Exception ex) { txtUpdateLog.AppendText("\n[ERROR] " + ex.Message + "\n\n"); } return rtnFlag; } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | private bool FtpFileExsit() { FtpWebRequest ftpWebRequest = WebRequest.Create(new Uri(ftpUri)) as FtpWebRequest; ftpWebRequest.Credentials = new NetworkCredential(this.userID, this.userPW); ftpWebRequest.UseBinary = true; ftpWebRequest.UsePassive = false; ftpWebRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails; FtpWebResponse response = null; string data = string.Empty; try { response = ftpWebRequest.GetResponse() as FtpWebResponse; if (response != null) { StreamReader streamReader = new StreamReader(response.GetResponseStream(), Encoding.Default); data = streamReader.ReadToEnd(); } } catch (Exception ex) { txtUpdateLog.AppendText("\n[ERROR] " + ex.Message + "\n\n"); } finally { if (response != null) { response.Close(); } } string[] directorys = data.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); return (from directory in directorys select directory.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries) into directoryInfos where directoryInfos[0][0] != 'd' select directoryInfos[8]).Any(name => name == programName); } | cs |
'C#' 카테고리의 다른 글
C# 카카오톡 핸들 찾기 (0) | 2021.02.23 |
---|---|
C# Excel 다운로드 (0) | 2019.09.27 |
C# 정규식을 이용하여 문자열이 숫자인지 판단 (0) | 2019.09.19 |
C# ListView 복사 붙여넣기 (0) | 2019.09.19 |
C# Excel을 PDF (0) | 2019.09.18 |