My.Computer.Network.DownloadFile 메서드

업데이트: 2007년 11월

지정한 원격 파일을 다운로드하여 지정한 위치에 저장합니다.

' Usage
My.Computer.Network.DownloadFile(address ,destinationFileName)
My.Computer.Network.DownloadFile(address ,destinationFileName)
My.Computer.Network.DownloadFile(address ,destinationFileName ,userName ,password)
My.Computer.Network.DownloadFile(address ,destinationFileName ,userName ,password)
My.Computer.Network.DownloadFile(address ,destinationFileName ,userName ,password ,showUI ,connectionTimeout ,overwrite)
My.Computer.Network.DownloadFile(address ,destinationFileName ,userName ,password ,showUI ,connectionTimeout ,overwrite ,onUserCancel)
My.Computer.Network.DownloadFile(address ,destinationFileName ,userName ,password ,showUI ,connectionTimeout ,overwrite)
My.Computer.Network.DownloadFile(address ,destinationFileName ,userName ,password ,showUI ,connectionTimeout ,overwrite ,onUserCancel)
My.Computer.Network.DownloadFile(address ,destinationFileName ,networkCredentials ,showUI ,connectionTimeout ,overwrite)
My.Computer.Network.DownloadFile(address ,destinationFileName ,networkCredentials ,showUI ,connectionTimeout ,overwrite ,onUserCancel)
' Declaration
Public Sub DownloadFile( _
   ByVal address As String, _
   ByVal destinationFileName As String _
)
' -or-
Public Sub DownloadFile( _
   ByVal address As System.Uri, _
   ByVal destinationFileName As String _
)
' -or-
Public Sub DownloadFile( _
   ByVal address As String, _
   ByVal destinationFileName As String, _
   ByVal userName As String, _
   ByVal password As String _
)
' -or-
Public Sub DownloadFile( _
   ByVal address As System.Uri, _
   ByVal destinationFileName As String, _
   ByVal userName As String, _
   ByVal password As String _
)
' -or-
Public Sub DownloadFile( _
   ByVal address As String, _
   ByVal destinationFileName As String, _
   ByVal userName As String, _
   ByVal password As String, _
   ByVal showUI As Boolean, _
   ByVal connectionTimeout As Integer, _
   ByVal overwrite As Boolean _
)
' -or-
Public Sub DownloadFile( _
   ByVal address As String, _
   ByVal destinationFileName As String, _
   ByVal userName As String, _
   ByVal password As String, _
   ByVal showUI As Boolean, _
   ByVal connectionTimeout As Integer, _
   ByVal overwrite As Boolean, _
   ByVal onUserCancel As UICancelOption _
)
' -or-
Public Sub DownloadFile( _
   ByVal address As System.Uri, _
   ByVal destinationFileName As String, _
   ByVal userName As String, _
   ByVal password As String, _
   ByVal showUI As Boolean, _
   ByVal connectionTimeout As Integer, _
   ByVal overwrite As Boolean _
)
' -or-
Public Sub DownloadFile( _
   ByVal address As System.Uri, _
   ByVal destinationFileName As String, _
   ByVal userName As String, _
   ByVal password As String, _
   ByVal showUI As Boolean, _
   ByVal connectionTimeout As Integer, _
   ByVal overwrite As Boolean, _
   ByVal onUserCancel As UICancelOption _
)
' -or-
Public Sub DownloadFile( _
   ByVal address As System.Uri, _
   ByVal destinationFileName As String, _
   ByVal networkCredentials As System.Net.ICredentials, _
   ByVal showUI As Boolean, _
   ByVal connectionTimeout As Integer, _
   ByVal overwrite As Boolean _
)
' -or-
Public Sub DownloadFile( _
   ByVal address As System.Uri, _
   ByVal destinationFileName As String, _
   ByVal networkCredentials As System.Net.ICredentials, _
   ByVal showUI As Boolean, _
   ByVal connectionTimeout As Integer, _
   ByVal overwrite As Boolean, _
   ByVal onUserCancel As UICancelOption _
)

매개 변수

  • address
    String 또는 Uri. 필수적 요소. 파일 이름과 호스트 주소를 포함하여 다운로드할 파일의 경로입니다.

  • destinationFileName
    필수적 요소. String. 다운로드한 파일의 이름과 경로입니다.

  • userName
    String. 인증할 사용자 이름입니다. 기본값은 빈 문자열("")입니다.

  • password
    String. 인증할 암호입니다. 기본값은 빈 문자열("")입니다.

  • showUI
    Boolean. 작업 진행률 표시 여부를 지정합니다. 기본값은 False입니다.

  • connectionTimeout
    Int32. 시간 제한 간격(밀리초)입니다. 기본값은 100초입니다.

  • overwrite
    Boolean. 기존 파일을 덮어쓸지 여부를 지정합니다. 기본값은 False입니다.

  • onUserCancel
    UICancelOption. ShowUI를 True로 설정하는 경우에 표시되는 대화 상자에서 사용자가 취소 또는 아니요를 클릭할 때의 동작을 지정합니다. 기본값은 ThrowException입니다.

  • networkCredentials
    ICredentials. 제공할 자격 증명입니다.

예외

다음 조건에서 예외가 throw될 수 있습니다.

설명

showUI를 True로 설정하면 작업 진행률을 표시하는 대화 상자가 나타납니다. 이 대화 상자에는 작업을 취소할 수 있는 취소 단추가 있습니다. 대화 상자가 모달이 아니므로 프로그램에서 다른 창에 대한 사용자 입력을 차단하지 않습니다.

서버가 지정한 connectionTimeout 이내에 응답하지 않으면 작업이 취소되고 예외가 throw됩니다.

응용 프로그램에서 네트워크 추적을 설정하면 DownloadFile에서 추적 정보를 출력합니다. 자세한 내용은 네트워크 추적 사용을 참조하십시오.

참고:

DownloadFile 메서드에서는 선택적 HTTP 헤더를 보내지 않습니다. 선택적 사용자 에이전트 헤더가 없는 경우 일부 서버에서 500(내부 서버 오류)를 반환할 수 있습니다. 선택적 헤더를 보내려면 WebClient 클래스를 사용하여 요청을 생성해야 합니다. 자세한 내용은 Visual Basic을 사용한 .NET Framework의 네트워크 작업을 참조하십시오.

보안 정보:

FTP 프로토콜은 암호 등의 정보를 일반 텍스트로 보내므로 중요한 정보를 전송할 때는 사용하지 말아야 합니다.

작업

다음 표에서는 My.Computer.Network.DownloadFile 메서드와 관련된 작업 예를 보여 줍니다.

작업

참조

파일 다운로드

방법: Visual Basic에서 파일 다운로드

예제

이 예제에서는 http://www.cohowinery.com/downloads에서 WineList.txt 파일을 다운로드하여 C:\Documents and Settings\All Users\Documents에 저장합니다.

My.Computer.Network.DownloadFile _
("http://www.cohowinery.com/downloads/WineList.txt", _
"C:\Documents and Settings\All Users\Documents\WineList.txt")

이 예제에서는 http://www.cohowinery.com/downloads에서 WineList.txt 파일을 다운로드하여 C:\Documents and Settings\All Users\Documents에 저장하고 시간 제한 간격을 500밀리초로 지정합니다.

My.Computer.Network.DownloadFile _
("http://www.cohowinery.com/downloads/", _
"C:\Documents and Settings\All Users\Documents\WineList.txt", _
"", "", False, 500, True)

요구 사항

네임스페이스:Microsoft.VisualBasic.Devices

클래스:Network

어셈블리: Visual Basic 런타임 라이브러리(Microsoft.VisualBasic.dll)

프로젝트 형식별 사용 가능 여부

프로젝트 형식

사용 가능 여부

Windows 응용 프로그램

클래스 라이브러리

콘솔 응용 프로그램

Windows 컨트롤 라이브러리

웹 컨트롤 라이브러리

Windows 서비스

웹 사이트

권한

다음과 같은 사용 권한이 필요합니다.

권한

설명

FileIOPermission

파일 및 폴더에 대한 액세스 가능성을 제어합니다. 연관된 열거형: Unrestricted

UIPermission

사용자 인터페이스 및 클립보드와 관련된 권한을 제어합니다. 연관된 열거형: AllWindows

WebPermission

HTTP 인터넷 리소스에 액세스할 수 있는 권한을 제어합니다. 연관된 열거형: Unrestricted

자세한 내용은 코드 액세스 보안권한 요청을 참조하십시오.

참고 항목

작업

방법: Visual Basic에서 파일 다운로드

방법: Visual Basic에서 원격 컴퓨터를 사용할 수 있는지 확인

방법: Visual Basic에서 파일 경로의 구문 분석

참조

My.Computer.Network 개체

System.Uri

System.Net.ICredentials

Network.DownloadFile