c# 에서 ftp로 파일 업로드 및 다운로드 하기
이렇게 만들었당 Fileinfo Fileinf는 다이얼로그 박스 열릴때 그 값 가져옴
private void ssw_image_upload(FileInfo fileinf)
{
string url = "ftp://" + serverip + fileinf.Name;
FtpWebRequest reqftp;
Console.WriteLine("1");
reqftp = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + serverip + fileinf.Name));
reqftp.Credentials = new NetworkCredential("cnc", "1111");
reqftp.KeepAlive = false;
reqftp.Method = WebRequestMethods.Ftp.UploadFile;
reqftp.UseBinary = true;
reqftp.ContentLength = fileinf.Length;
int bufflen = 2048; // 2kb
byte[] buff = new byte[bufflen];
int contentlen;
FileStream fs = fileinf.OpenRead();
Stream strm = reqftp.GetRequestStream();
contentlen = fs.Read(buff, 0, bufflen);
while (contentlen != 0)
{
strm.Write(buff, 0, contentlen);
contentlen = fs.Read(buff, 0, bufflen);
}
strm.Close();
fs.Close();
}
private void ssw_image_download(string img_name)
{
WebClient wc = new WebClient();
wc.Credentials = new NetworkCredential("cnc", "1111");
wc.DownloadFile("ftp://" + serverip + img_name, "c:/check/"+img_name);
}