이벤트에 다음과 같이 소스를 작성해서 실행하면 됩니다~
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Try
'다운로드할 ftp주소
Dim u As New Uri(System.IO.Path.Combine("ftp://127.0.0.0/aa/bb/cc/", fileName))
Dim u As New Uri(System.IO.Path.Combine("ftp://127.0.0.0/aa/bb/cc/", "불량코드.txt"))
'c:에 다운로드
'Dim downFile As String = System.IO.Path.Combine("D:\Project\FileToDB\File\", fileName)
Dim downFile As String = System.IO.Path.Combine("C:\Users\hhhwang\Desktop", "불량코드.txt")
'리퀘스트작성
Dim ftpReq As System.Net.FtpWebRequest = CType(System.Net.WebRequest.Create(u), System.Net.FtpWebRequest)
'아이디,비번입력
ftpReq.Credentials = New System.Net.NetworkCredential("아이디", "비번")
'리퀘스트메소드에 다운로드
ftpReq.Method = System.Net.WebRequestMethods.Ftp.DownloadFile
ftpReq.KeepAlive = False
ftpReq.UseBinary = False
ftpReq.UsePassive = False
'리스폰스취득
Dim ftpRes As System.Net.FtpWebResponse = CType(ftpReq.GetResponse(), System.Net.FtpWebResponse)
'화일 다운로드하기위에 스트림취득
Dim resStrm As System.IO.Stream = ftpRes.GetResponseStream()
'다운로드할 화일을 엽니다.
Dim fs As System.IO.FileStream = New System.IO.FileStream(downFile, System.IO.FileMode.Create, System.IO.FileAccess.Write)
'전송
Dim buffer(1024) As Byte
While (True)
Dim readSize As Integer = resStrm.Read(buffer, 0, buffer.Length)
If (readSize = 0) Then
Exit While
End If
fs.Write(buffer, 0, readSize)
End While
fs.Close()
resStrm.Close()
Catch ex As Exception
'Throw New Exception(ex.Message)
System.Windows.Forms.MessageBox.Show(ex.ToString())
End Try
End Sub
'Visual Std 2010' 카테고리의 다른 글
Datagridview 원하는 행으로 이동 (0) | 2015.09.14 |
---|---|
FTP 컴포넌트를 이용해 파일 받아오기 (0) | 2015.09.14 |
DB에서 저장된 이미지 PictureBox로 불러오기 (0) | 2015.09.14 |
txt파일 읽어서 DB에 저장 (0) | 2015.09.14 |
VisualStudio2010 , MSSQL2008 이미지 컨트롤 (Stream 사용) (0) | 2015.09.14 |