C#

초간단 FTP

by LionHeart posted Jan 29, 2014
?

단축키

Prev이전 문서

Next다음 문서

ESC닫기

크게 작게 위로 아래로 댓글로 가기 인쇄

URL: http://blog.naver.com/PostView.nhn?blogId=doghole&logNo=100101473880


FTP로 파일 업로드 할 때 사용하는 C# 코드 입니다.

FtpWebRequest 클래스로 간단하게 구현 할 수 있어서 정말 다행입니다.


string ftpfullpath = "ftp 주소 (ftp 로 올려질 파일 주소 ex:ftp://123.123.123.123/test/test.txt)";
FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);
ftp.Credentials = 
new NetworkCredential("ftp 아이디", "ftp 비밀번호");

ftp.KeepAlive = 
false;
ftp.UseBinary = 
true;
ftp.UsePassive = 
false;
                
ftp.Method = WebRequestMethods.Ftp.UploadFile;
FileStream fs = File.OpenRead(inputfilepath);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
fs.Close();
                
Stream ftpstream = ftp.GetRequestStream();
ftpstream.Write(buffer, 0, buffer.Length);
ftpstream.Close();
ftp.Abort();

[출처] [C#] FTP 파일 업로드|작성자 dogholeRRR