C# FTP 서버로 파일업로드질문이요!
글쓴이: majestic / 작성시간: 금, 2018/11/09 - 4:20오후
private string FtpAddress = "ftp://000.000.000.000/AAA"; private string FtpId = "test"; private string FtpPw = "1"; private string FtpPath = "/"; private string FileName = "PI21374_출하검사성적서.xls"; private string localPath = @"C:/ex"; private void button1_Click(object sender, EventArgs e) { try { FtpWebRequest requestFTPUploader = (FtpWebRequest)WebRequest.Create(FtpAddress + FtpPath + FileName); requestFTPUploader.Credentials = new NetworkCredential(FtpId, FtpPw); requestFTPUploader.Method = WebRequestMethods.Ftp.UploadFile; FileInfo fileInfo = new FileInfo(FileName); FileStream fileStream = fileInfo.OpenRead(); int bufferLength = 2048; 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 eorror) { MessageBox.Show(eorror.Message); } } 윈폼으로 버튼하나 누르면 ftp 서버로 파일업로드에 관해 코드수정중인데 localPath 경로지정을 하긴했는데 소스에서 로컬경로를 어디다 넣어야할지, 수정해야할지 모르겠네요..ㅠㅠ
Forums:
댓글 달기