| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
- Gradient
- Filtering
- mfc
- Class
- UNO
- subpixel
- flutter
- Read
- file access
- digitalRead
- Android
- Binary
- Contour
- SERIAL
- memory
- atmega328
- sensor
- wpf
- stream
- Pointer
- aduino
- c++
- APP
- edge
- parameter
- compare
- public
- Encapusulation
- Gaussian
- Unity
- Today
- Total
폴크(FOLC)
C# 테크닉 - FTP FileDownload ( WebRequest ) 본문
C# 테크닉 - FTP FileDownload ( WebRequest )
folcjin 2021. 12. 5. 19:53# FTP : File Transfer Protocol은 TCP/IP 프로토콜을 가지고 있어서 서버(HOST)와 모듈(CLIENT) 사이의 파일 송/수신
> TCP/IP 프로토콜 테이블의 응용 계층
> 운영 체제가 그래픽 사용자 인터페이스를 갖추기 이전에 개발된 명령 줄 프로그램
> 대부분의 윈도우, 유닉스, 리눅스 운영 체제에 기본 포함되어 있다.
# 소스 코드
public bool FileDownload(string src_path, string dst_path, string user_id, string user_pw)
{
try
{
Uri src_file_uri = new Uri(src_path);
FtpWebRequest ftpWebReq = WebRequest.Create(src_file_uri) as FtpWebRequest;
ftpWebReq.Credentials = new NetworkCredential(user_id, user_pw);
ftpWebReq.Method = WebRequestMethods.Ftp.DownloadFile;
FtpWebResponse ftpWebRes = ftpWebReq.GetResponse() as FtpWebResponse;
Stream src_file_stream = ftpWebRes.GetResponseStream();
FileStream dst_file_stream = new FileStream(dst_path, FileMode.Create, FileAccess.Write);
byte[] databufferArray = new byte[1024];
while (true)
{
int data_count = src_file_stream.Read(databufferArray, 0, databufferArray.Length);
if (data_count == 0) { break; }
dst_file_stream.Write(databufferArray, 0, data_count);
}
dst_file_stream.Close();
src_file_stream.Close();
}
catch
{
return false;
}
return true;
}
'C#, WF, WPF(.NET) > C#, WF, WPF(.NET) 테크닉' 카테고리의 다른 글
| C# 테크닉 - UnZip 파일 복원 ( SharpZipLib ) (0) | 2021.12.06 |
|---|---|
| C# 테크닉 - Zip 파일 생성( SharpZipLib ) (0) | 2021.12.06 |
| C# 테크닉 - FTP FileUpload ( WebRequest ) (0) | 2021.12.05 |
| C# 테크닉 - 파일 제어( CSV format ) (0) | 2021.12.04 |
| WPF 테크닉 - Chart 그리기 ( LiveCharts ) (0) | 2021.12.03 |