운영체제/Linux

wget 명령어를 이용한 파일 다운로드

ahgle 2022. 9. 19. 14:22
728x90
반응형

wget

웹에서 파일 다운로드를 도와주는 리눅스 커맨드라인 유틸리티이다. HTTP, HTTPS, FTP 프로토콜을 이용하여 파일을 다운로드할 수 있다.

여러 파일을 다운로드하고, 대역폭을 제한하거나, 분할해서 다운로드 하는 등 다양한 옵션을 제공한다.

 

wget이 설치돼있다면 아래와 같이 wget 명령어만 입력 시, missing URL이라는 문구가 나올 것이다.

 

wget으로 가져올 URL을 입력해야하나, 입력하지 않아 발생하는 것이다.

[root@test]wget
wget: missing URL

 

 

아무런 옵션 없이, wget명령어를 이용하여 다운로드해보자. LINUX용 VSCODE를 다운받기 위해 아래 URL을 이용했다.

 

기본형식

wget 도메인주소(서버주소)

 

https://update.code.visualstudio.com/commit:74b1f979648cc44d385a2286793c226e611f59e7/server-linux-x64/stable

 

[root@test]wget https://update.code.visualstudio.com/commit:74b1f979648cc44d385a2286793c226e611f59e7/server-linux-x64/stable                     
--2022-09-19 13:57:16--  https://update.code.visualstudio.com/commit:74b1f979648cc44d385a2286793c226e611f59e7/server-linux-x64/stable
Resolving update.code.visualstudio.com (update.code.visualstudio.com)... 20.43.132.130
Connecting to update.code.visualstudio.com (update.code.visualstudio.com)|20.43.132.130|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://az764295.vo.msecnd.net/stable/74b1f979648cc44d385a2286793c226e611f59e7/vscode-server-linux-x64.tar.gz [following]
--2022-09-19 13:57:16--  https://az764295.vo.msecnd.net/stable/74b1f979648cc44d385a2286793c226e611f59e7/vscode-server-linux-x64.tar.gz
Resolving az764295.vo.msecnd.net (az764295.vo.msecnd.net)... 117.18.232.200
Connecting to az764295.vo.msecnd.net (az764295.vo.msecnd.net)|117.18.232.200|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 58366521 (56M) [application/gzip]
Saving to: ‘stable’

100%[=====================================================================================================================================================================>] 58,366,521  8.57MB/s   in 8.7s   

2022-09-19 13:57:26 (6.42 MB/s) - ‘stable’ saved [58366521/58366521]

 

wget명령어를 이용하니 도메인에 대한 IP 주소를 확인(20.43.132.130) 후 원격서버에 연결, 파일 전송을 시작한다.

다운로드 완료 후엔 완료 시간, 초 당 다운로드 속도, 파일명, 파일 크기 등이 출력된다.

2022-09-19 13:57:26 (6.42 MB/s) - ‘stable’ saved [58366521/58366521]

 

파일이 이미 있는 경우, 파일 이름끝에 아래와 같이 [파일명.숫자]로 추가된다.

-rw-r--r-- 1 root root 58366521 Sep 15 06:43 stable
-rw-r--r-- 1 root root 58366521 Sep 15 06:43 stable.1

 

FTP 서버에서 다운로드하기

wget을 통해  익명 ftp를 통해 파일 다운로드가 가능하다. FTP는 로그인을 필요로 하지 않는다.

wget ftp://test.com/file.tar.gz

 

신뢰할 수 없는 https URL에서 파일을 다운로드하는 방법

-no-check-certificate 옵션을 사용하여 신뢰할 수 없는 사이트에서의 유효성 검사를 무시하고 다운로드가 가능하다.

wget http://test.com/file.tar.gz -no-check-certificate

 

전체 웹사이트 미러링

-m 옵션을 이용하여 미러링을 설정한다. 모든 웹사이트의 파일을 다운로드할 수 있다.

wget -m http://test.com

테스트 시 테스트용으로 운영중인 사이트이지만(실제 url은 다릅니다)

-m 옵션 이용했을 때 사이트 내의 모든 파일들이 아래와 같이 다운로드 되는 것을 보고 충격먹었다.보안 상 큰 취약점이기 때문에 대부분의 사이트들은 wget을 통한 파일 다운로드 접근을 막아놓았을 것이다.

2022-09-19 14:14:56 (90.6 MB/s) - ‘test.com/bbs/board.php?bo_table=qa&sop=and&sst=wr_hit&sod=asc&sfl=&stx=&sca=&page=1&device=mobile’ saved [14781]

--2022-09-19 14:14:56--  http://test.com/bbs/board.php?bo_table=qa&sop=and&sst=wr_datetime&sod=asc&sfl=&stx=&sca=&page=1&device=mobile
Reusing existing connection to test.com:80.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: ‘test.com/bbs/board.php?bo_table=qa&sop=and&sst=wr_datetime&sod=asc&sfl=&stx=&sca=&page=1&device=mobile’

    [ <=>                                                                                                                                                                  ] 14,796      --.-K/s   in 0s      

...... 반복 다운로드 과정 생략 ......

--2022-09-19 14:14:56--  http://testcom/bbs/board.php?bo_table=notice&sop=and&sst=wr_datetime&sod=asc&sfl=&stx=&sca=&page=1&device=mobile
Reusing existing connection to test.com:80.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: ‘test.com/bbs/board.php?bo_table=notice&sop=and&sst=wr_datetime&sod=asc&sfl=&stx=&sca=&page=1&device=mobile’

    [ <=>                                                                                                                                                                  ] 13,878      --.-K/s   in 0s      

2022-09-19 14:14:56 (172 MB/s) - ‘test.com/bbs/board.php?bo_table=notice&sop=and&sst=wr_datetime&sod=asc&sfl=&stx=&sca=&page=1&device=mobile’ saved [13878]

FINISHED --2022-09-19 14:14:56--

 

파일 다운로드 중 다운로드 속도를 제한

-limit-rate=속도 옵션을 이용하여 다운로드 속도를 제한할 수 있다.

wget -limit-rate=1024k http://test.com/file.tar.gz

 

 

다운로드하다 중단된 파일 다시 이어받기

-c 옵션을 이용하여 중단된 다운로드를 재개할 수 있다.

 

wget -c http://test.com/file.tar.gz​
728x90