반응형

안녕하세요 가야태자 @talkit 입니다.

wget은 웹(http,https), FTP를 통해서 파일을 다운로드하게 해주는 고마운 툴입니다.

![[Pasted image 20230108221214.png]]

wget 의 설명을 보려면 리눅스에서

man wget

이라고 치십시오.

그러면 다양한 옵션들이 있습니다. ^^

제가 공부해보려고 하는 내용은 웹에서 다운로드하기 와 ftp에서 다운로드 하기 입니다.

기본 사용법

리눅스 명령어의 기본 사용법은 거의 비슷합니다.

wget [옵션들] 다운로드할 주소

옵션들은 생략이 가능 합니다. ^^

주소는 무조건 있어야 합니다.

web과 ftp는 주소에서 드립니다.

http:// 또는 https:// 로 시작하면 web에서 다운로드하는 것이구요.

ftp:// 에서 다운로드하면 FTP에서 다운로드 하는 것입니다.

web에서 다운로드하기

웹에서 다운로드는 웹 주소만 잘 주시면 됩니다 .^^

일반적으로 제가 프로그램을 다운로드할때 wget을 쓰는 모습을 보셨을 겁니다.

오늘은 네이버의 로고를 한번 다운로드 받아 볼텐데 실제 로고인지는 잘 모르겠습니다. ^^

https://s.pstatic.net/static/www/img/uit/sp_main_947f65.png

오 클릭해보니 맞네요

저 파일을 내려 받아 보겠습니다.

wget https://s.pstatic.net/static/www/img/uit/sp_main_947f65.png

저 명령어를 제가 리눅스에 넣었습니다.

wget https://s.pstatic.net/static/www/img/uit/sp_main_947f65.png
--2023-01-08 05:18:35--  https://s.pstatic.net/static/www/img/uit/sp_main_947f65.png
Resolving s.pstatic.net (s.pstatic.net)... 125.209.254.152, 125.209.254.148, 125.209.254.150, ...
Connecting to s.pstatic.net (s.pstatic.net)|125.209.254.152|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 243162 (237K) [image/png]
Saving to: ‘sp_main_947f65.png’

sp_main_947f65.png                                          100%[========================================================================================================================================>] 237.46K  --.-KB/s    in 0.02s

2023-01-08 05:18:35 (10.2 MB/s) - ‘sp_main_947f65.png’ saved [243162/243162]

이렇게 잘 나오네요 ^^

그런데 웹에 있는 파일명 그대로 다운로드가 됩니다.

이번에는 .png 파일이 정의되어 있어서 잘 다운로드가 되었지만, ^^

가끔

wget -O naverlogo.png  https://s.pstatic.net/static/www/img/uit/sp_main_947f65.png

주소가 저따위로 되어 있으면 ^^ 파일명이 거의 저모습 그대로 저장 됩니다.

그래서,

web에서는 -O 옵션이 중요할 것같습니다.

talkit@ubuntu:~$ ls
Desktop    emmptydir2  emmptydir5     ftpserver11.txt  ftpserver14.txt  ftpserver32.txt  ftpserver35.txt  ftpserver5.txt                       minio.deb  Public              study      testtext.txt
Documents  emmptydir3  emptydir       ftpserver12.txt  ftpserver15.txt  ftpserver33.txt  ftpserver3.txt   ftpserver.txt                        Music      snap                temp       Videos
Downloads  emmptydir4  ftpclient.txt  ftpserver13.txt  ftpserver31.txt  ftpserver34.txt  ftpserver4.txt   mattermost-7.5.2-linux-amd64.tar.gz  Pictures   sp_main_947f65.png  Templates

저기 파일이 다운로드 되어 있습니다.

그런데, naverlogo.png로 변경하려면 어떻게 해야 할까요?

http://도메인주소/abcdefgh.do?dkjalsf=askldfjalksdj&aksdfja=ajskldfja
wget -O naverlogo.png https://s.pstatic.net/static/www/img/uit/sp_main_947f65.png
--2023-01-08 05:22:34--  https://s.pstatic.net/static/www/img/uit/sp_main_947f65.png
Resolving s.pstatic.net (s.pstatic.net)... 125.209.254.152, 125.209.254.148, 125.209.254.150, ...
Connecting to s.pstatic.net (s.pstatic.net)|125.209.254.152|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 243162 (237K) [image/png]
Saving to: ‘naverlogo.png’

naverlogo.png                                               100%[========================================================================================================================================>] 237.46K  --.-KB/s    in 0.02s

2023-01-08 05:22:34 (10.7 MB/s) - ‘naverlogo.png’ saved [243162/243162]

talkit@ubuntu:~$ ls
Desktop    emmptydir2  emmptydir5     ftpserver11.txt  ftpserver14.txt  ftpserver32.txt  ftpserver35.txt  ftpserver5.txt                       minio.deb      Pictures  sp_main_947f65.png  Templates
Documents  emmptydir3  emptydir       ftpserver12.txt  ftpserver15.txt  ftpserver33.txt  ftpserver3.txt   ftpserver.txt                        Music          Public    study               testtext.txt
Downloads  emmptydir4  ftpclient.txt  ftpserver13.txt  ftpserver31.txt  ftpserver34.txt  ftpserver4.txt   mattermost-7.5.2-linux-amd64.tar.gz  naverlogo.png  snap      temp                Videos

잘 저장이 되었습니다.

저기 naverlog.png 보이시지요 ^^

다운로드 받으실 주소를 복사하시고

wget 명령어 뒤에다가 넣어 주시면 되고

-O 옵션을 기억 하시면 될 것 같습니다.

개별 파일의 경우 -O 옵션은 FTP에서도 가능 합니다.

ftp에서 다운로드하기

FTP options:
       --ftp-user=USER             set ftp user to USER
       --ftp-password=PASS         set ftp password to PASS
       --no-remove-listing         don't remove '.listing' files
       --no-glob                   turn off FTP file name globbing
       --no-passive-ftp            disable the "passive" transfer mode
       --preserve-permissions      preserve remote file permissions
       --retr-symlinks             when recursing, get linked-to files (not dir)

FTP 관련 옵션위와 같습니다. ^^
저기서 3가지 정도를 사용해야 합니다.

--ftp-user= ftp 사용자아이디
--ftp-password= ftp 사용자패스워드
--no-passive-ftp

위세가지 옵션을 이용해서 한번 다운로드 해보겠습니다

wget --ftp-user=사용자아이디 --ftp-password=비밀번호 [--no-passive-ftp] 다운로드주소

FTP도 동일하게 다운로드여서 무조건 다운로드 주소는 있어야 합니다.

한번 제가 지난 번에 만들어 둔 ftp로 다운을 받아 보겠습니다.

내부 FTP여서 ^^

wget --ftp-user=talkit --ftp-password=비밀번호 ftp://192.168.0.27:21/ftp*
wget --ftp-user=talkit --ftp-password=비빌번호 ftp://192.168.0.27:21/ftp*
--2023-01-08 06:10:19--  ftp://192.168.0.27/ftp*
           => ‘.listing’
Connecting to 192.168.0.27:21... connected.
Logging in as talkit ... Logged in!
==> SYST ... done.    ==> PWD ... done.
==> TYPE I ... done.  ==> CWD not needed.
==> PASV ... done.    ==> LIST ... done.

.listing                                                        [ <=>                                                                                                                                     ]   3.36K  --.-KB/s    in 0s

2023-01-08 06:10:20 (24.1 MB/s) - ‘.listing’ saved [3445]

Removed ‘.listing’.
--2023-01-08 06:10:20--  ftp://192.168.0.27/ftpclient.txt
           => ‘ftpclient.txt’
==> CWD not required.
==> PASV ... done.    ==> RETR ftpclient.txt ... done.
Length: 35

ftpclient.txt                                               100%[========================================================================================================================================>]      35  --.-KB/s    in 0.01s

2023-01-08 06:10:20 (2.91 KB/s) - ‘ftpclient.txt’ saved [35]

--2023-01-08 06:10:20--  ftp://192.168.0.27/ftpserver.txt
           => ‘ftpserver.txt’
==> CWD not required.
==> PASV ... done.    ==> RETR ftpserver.txt ... done.
Length: 35

ftpserver.txt                                               100%[========================================================================================================================================>]      35  --.-KB/s    in 0.02s

2023-01-08 06:10:20 (2.20 KB/s) - ‘ftpserver.txt’ saved [35]

--2023-01-08 06:10:20--  ftp://192.168.0.27/ftpserver11.txt
           => ‘ftpserver11.txt’
==> CWD not required.
==> PASV ... done.    ==> RETR ftpserver11.txt ... done.
Length: 35

ftpserver11.txt                                             100%[========================================================================================================================================>]      35  --.-KB/s    in 0.006s

2023-01-08 06:10:20 (5.26 KB/s) - ‘ftpserver11.txt’ saved [35]

--2023-01-08 06:10:20--  ftp://192.168.0.27/ftpserver12.txt
           => ‘ftpserver12.txt’
==> CWD not required.
==> PASV ... done.    ==> RETR ftpserver12.txt ... done.
Length: 35

ftpserver12.txt                                             100%[========================================================================================================================================>]      35  --.-KB/s    in 0.007s

2023-01-08 06:10:20 (5.07 KB/s) - ‘ftpserver12.txt’ saved [35]

--2023-01-08 06:10:20--  ftp://192.168.0.27/ftpserver13.txt
           => ‘ftpserver13.txt’
==> CWD not required.
==> PASV ... done.    ==> RETR ftpserver13.txt ... done.
Length: 35

ftpserver13.txt                                             100%[========================================================================================================================================>]      35  --.-KB/s    in 0.006s

2023-01-08 06:10:20 (5.35 KB/s) - ‘ftpserver13.txt’ saved [35]

--2023-01-08 06:10:20--  ftp://192.168.0.27/ftpserver14.txt
           => ‘ftpserver14.txt’
==> CWD not required.
==> PASV ... done.    ==> RETR ftpserver14.txt ... done.
Length: 35

ftpserver14.txt                                             100%[========================================================================================================================================>]      35  --.-KB/s    in 0.009s

2023-01-08 06:10:20 (3.61 KB/s) - ‘ftpserver14.txt’ saved [35]

--2023-01-08 06:10:20--  ftp://192.168.0.27/ftpserver15.txt
           => ‘ftpserver15.txt’
==> CWD not required.
==> PASV ... done.    ==> RETR ftpserver15.txt ... done.
Length: 35

ftpserver15.txt                                             100%[========================================================================================================================================>]      35  --.-KB/s    in 0s

2023-01-08 06:10:20 (97.6 KB/s) - ‘ftpserver15.txt’ saved [35]

--2023-01-08 06:10:20--  ftp://192.168.0.27/ftpserver3.txt
           => ‘ftpserver3.txt’
==> CWD not required.
==> PASV ... done.    ==> RETR ftpserver3.txt ... done.
Length: 35

ftpserver3.txt                                              100%[========================================================================================================================================>]      35  --.-KB/s    in 0s

2023-01-08 06:10:20 (72.0 KB/s) - ‘ftpserver3.txt’ saved [35]

--2023-01-08 06:10:20--  ftp://192.168.0.27/ftpserver31.txt
           => ‘ftpserver31.txt’
==> CWD not required.
==> PASV ... done.    ==> RETR ftpserver31.txt ... done.
Length: 35

ftpserver31.txt                                             100%[========================================================================================================================================>]      35  --.-KB/s    in 0.002s

2023-01-08 06:10:20 (20.0 KB/s) - ‘ftpserver31.txt’ saved [35]

--2023-01-08 06:10:20--  ftp://192.168.0.27/ftpserver32.txt
           => ‘ftpserver32.txt’
==> CWD not required.
==> PASV ... done.    ==> RETR ftpserver32.txt ... done.
Length: 35

ftpserver32.txt                                             100%[========================================================================================================================================>]      35  --.-KB/s    in 0s

2023-01-08 06:10:20 (139 KB/s) - ‘ftpserver32.txt’ saved [35]

--2023-01-08 06:10:20--  ftp://192.168.0.27/ftpserver33.txt
           => ‘ftpserver33.txt’
==> CWD not required.
==> PASV ... done.    ==> RETR ftpserver33.txt ... done.
Length: 35

ftpserver33.txt                                             100%[========================================================================================================================================>]      35  --.-KB/s    in 0.002s

2023-01-08 06:10:20 (14.7 KB/s) - ‘ftpserver33.txt’ saved [35]

--2023-01-08 06:10:20--  ftp://192.168.0.27/ftpserver34.txt
           => ‘ftpserver34.txt’
==> CWD not required.
==> PASV ... done.    ==> RETR ftpserver34.txt ... done.
Length: 35

ftpserver34.txt                                             100%[========================================================================================================================================>]      35  --.-KB/s    in 0.002s

2023-01-08 06:10:20 (18.7 KB/s) - ‘ftpserver34.txt’ saved [35]

--2023-01-08 06:10:20--  ftp://192.168.0.27/ftpserver35.txt
           => ‘ftpserver35.txt’
==> CWD not required.
==> PASV ... done.    ==> RETR ftpserver35.txt ... done.
Length: 35

ftpserver35.txt                                             100%[========================================================================================================================================>]      35  --.-KB/s    in 0s

2023-01-08 06:10:20 (127 KB/s) - ‘ftpserver35.txt’ saved [35]

--2023-01-08 06:10:20--  ftp://192.168.0.27/ftpserver4.txt
           => ‘ftpserver4.txt’
==> CWD not required.
==> PASV ... done.    ==> RETR ftpserver4.txt ... done.
Length: 35

ftpserver4.txt                                              100%[========================================================================================================================================>]      35  --.-KB/s    in 0s

2023-01-08 06:10:20 (147 KB/s) - ‘ftpserver4.txt’ saved [35]

--2023-01-08 06:10:20--  ftp://192.168.0.27/ftpserver5.txt
           => ‘ftpserver5.txt’
==> CWD not required.
==> PASV ... done.    ==> RETR ftpserver5.txt ... done.
Length: 35

ftpserver5.txt                                              100%[========================================================================================================================================>]      35  --.-KB/s    in 0s

위와 같이 사용 가능 합니다. ^^

ftp로 시작하는 아이들이 잘 다운로드 되었습니다.

 ls
ftpclient.txt    ftpserver12.txt  ftpserver14.txt  ftpserver31.txt  ftpserver33.txt  ftpserver35.txt  ftpserver4.txt  ftpserver.txt
ftpserver11.txt  ftpserver13.txt  ftpserver15.txt  ftpserver32.txt  ftpserver34.txt  ftpserver3.txt   ftpserver5.txt

유용한 옵션 --mirror

홈페이지나 오픈소스를 하다보면 백업을 해야할 경우가 있습니다.

wget --mirror --ftp-user=talkit --ftp-password=비빌번호 ftp://192.168.0.27:21/*

talkit 계정을 미러링 해보겠습니다. ^^

 cd 192.168.0.27/
talkt2@ubuntu:~/wgettest/192.168.0.27$ ls
Desktop    emmptydir2  emmptydir5     ftpserver11.txt  ftpserver14.txt  ftpserver32.txt  ftpserver35.txt  ftpserver5.txt                       minio.deb      Pictures  sp_main_947f65.png  Templates     wgettest
Documents  emmptydir3  emptydir       ftpserver12.txt  ftpserver15.txt  ftpserver33.txt  ftpserver3.txt   ftpserver.txt                        Music          Public    study               testtext.txt
Downloads  emmptydir4  ftpclient.txt  ftpserver13.txt  ftpserver31.txt  ftpserver34.txt  ftpserver4.txt   mattermost-7.5.2-linux-amd64.tar.gz  naverlogo.png  snap      temp                Videos

미러링은 잘 되었습니다.

결론

wget 은 정말 고마운 툴입니다.

요즘은 또 유행하고 있는 것이 curl 이 유행을 하고 있어서 한번 글을 언젠가 적어 보겠습니다.

감샇합니다.

#linux #command #wget

반응형

+ Recent posts