서버/Linux III 2016. 3. 15. 13:33

Linux III - 06. FTP 클라이언트

 

 

 

login as: root
root@192.168.1.100's password:
Last login: Tue Mar 15 10:45:40 2016 from 192.168.1.1
[root@main /root]#

 

login as: root
root@192.168.1.101's password:
Last login: Tue Mar 15 14:25:53 2016 from 192.168.1.1
[root@clone1 /root]#

 

 

 

 

1. FTP 패키지 설치 및 서비스 활성화

 

 - main에서 FTP 서버 패키지를 설치한 이후, 서비스를 활성화시킨다.

 

[root@main /root]# yum list vsftpd
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: centos.tt.co.kr
 * extras: mirror.oasis.onnetcorp.com
 * updates: mirror.oasis.onnetcorp.com
Installed Packages
vsftpd.x86_64     2.2.2-12.el6_5.1      @anaconda-CentOS-201410241409.x86_64/6.6
Available Packages
vsftpd.x86_64     2.2.2-14.el6          base

 

 

[root@main /root]# yum -y install vsftpd



[root@main /root]# service vsftpd start
vsftpd에 대한 vsftpd을 시작 중:                            [  OK  ]

 


[root@main /root]# pgrep -l vsftpd
5068 vsftpd

 

 

 

 - main에서 SElinux가 사용중이면, 일반 계정으로 FTP 서버 로그인이 안될수 있다.

 

[root@main /root]# sestatus
SELinux status:                 enabled
SELinuxfs mount:                /selinux
Current mode:                   enforcing
Mode from config file:          enforcing
Policy version:                 24
Policy from config file:        targeted

 

 


 - 이런 경우 다음과 같이 ' ftp_home_dir' 부분을 'on'으로 변경하면 된다.

 

[root@main /root]# getsebool -a | grep ftp
allow_ftpd_anon_write --> off
allow_ftpd_full_access --> off
allow_ftpd_use_cifs --> off
allow_ftpd_use_nfs --> off
ftp_home_dir --> off  <- on 수정
ftpd_connect_db --> off
ftpd_use_fusefs --> off
ftpd_use_passive_mode --> off
httpd_enable_ftp_server --> off
tftp_anon_write --> off
tftp_use_cifs --> off
tftp_use_nfs --> off

[root@main /root]# setsebool -P ftp_home_dir on

[root@main /root]# getsebool -a | grep ftp
allow_ftpd_anon_write --> off
allow_ftpd_full_access --> off
allow_ftpd_use_cifs --> off
allow_ftpd_use_nfs --> off
ftp_home_dir --> on
ftpd_connect_db --> off
ftpd_use_fusefs --> off
ftpd_use_passive_mode --> off
httpd_enable_ftp_server --> off
tftp_anon_write --> off
tftp_use_cifs --> off
tftp_use_nfs --> off

 

 

 - 재부팅시 vsftpd 서비스가 자동으로 시작되도록 구성한다.

 

[root@main /root]# who -r
         run-level 5  2016-03-16 13:33

 

 

[root@main /root]# ls /etc/rc5.d/*ftp*
/etc/rc5.d/K50vsftpd

 

 

[root@main /root]# chkconfig --level 5 vsftpd on

 

 

[root@main /root]# ls /etc/rc5.d/*ftp*
/etc/rc5.d/S60vsftpd

 

 

[root@main /root]# chkconfig --list vsftpd
vsftpd          0:해제  1:해제  2:해제  3:해제  4:해제  5:활성  6:해제

 

 

[root@main /root]# reboot

 

 

 

 

2. FTP 클라이언트 패키지 설치

 

 -  clone1, clone2에서 FTP 클라이언트 패키지를 설치한 이후, 서비스를 활성화시킨다.
 

[root@clone1 /root]# yum list ftp
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: centos.tt.co.kr
 * extras: mirror.oasis.onnetcorp.com
 * updates: mirror.oasis.onnetcorp.com
Available Packages
ftp.x86_64                           0.17-54.el6                            base

 

 

[root@clone1 /root]# yum -y install ftp

 

 

[root@clone2 /root]# yum list ftp
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: centos.tt.co.kr
 * extras: mirror.oasis.onnetcorp.com
 * updates: mirror.oasis.onnetcorp.com
Available Packages
ftp.x86_64                           0.17-54.el6                            base

 

 

[root@clone2 /root]# yum -y install ftp


 

 

 

3. FTP 접속 및 명령어

 

[root@clone1 /root]# ftp
ftp> help
Commands may be abbreviated.  Commands are:

!               debug           mdir            sendport        site
$               dir             mget            put             size
account         disconnect      mkdir           pwd             status
append          exit            mls             quit            struct
ascii           form            mode            quote           system
bell            get             modtime         recv            sunique
binary          glob            mput            reget           tenex
bye             hash            newer           rstatus         tick
case            help            nmap            rhelp           trace
cd              idle            nlist           rename          type
cdup            image           ntrans          reset           user
chmod           lcd             open            restart         umask
close           ls              prompt          rmdir           verbose
cr              macdef          passive         runique         ?
delete          mdelete         proxy           send


ftp>
ftp> quit
[root@clone1 /root]#

 

 

 [자주 사용하는 FTP 명령어]

 명령어

설명 

 open

  FTP 서버 접속

 user

  로그인 실패시 다시 로그인할때 사용

 !

  FTP 프롬프트에서 쉘 명령어 사용

 acsii

  전송 모드를 ACSII 타입으로 지정

 bin

  전송 모드를 Binary 타입으로 지정

 get

  하나의 파일을 다운로드 실시

 mget

  다수의 파일들을 다운로드 실시

 put

  하나의 파일을 업로드 실시

 mput

  다수의 파일들을 업로드 실시

 cd

  디렉토리 변경/이동

 mkdir

  디렉토리 생성

 rmdir

  디렉토리 삭제

 hash

  파일송수신시 '#' 마크를 이용하여 전송상태 표시

 prompt

  비대화식 파일 송수신

 close

  접속 종료

 quit

  FTP를 종료하고 쉘로 돌아감

 user

  로그인시 ID, 패스워드가 틀린 경우, 다시 입력함

 lcd

  서버가 아닌 클라이언트의 현재 디렉토리를 변경함 Ex : lcd /tmp

 

 

 - clome1에서 main으로 FTP 접속을 실시한다. (user1 계정 사용)

 

[root@clone1 /root]# ftp
ftp> open main
Connected to main (172.20.1.1).
220 (vsFTPd 2.2.2)
Name (main:root): user1
331 Please specify the password.
Password: centos
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
ftp>

 

 

[참고] 대표적인 FTP 응답 코드

 220

  Service ready for new user

 230

  User logged on, proceed 

 331

  User name okay, need password

 530

  Not logged in

 221

  Service closing TELNET connection

 

 

 

 

Ex1) 대화식 파일 다운로드

 

ftp>
ftp> pwd   <- main 서버의 현재 디렉토리 확인
257 "/home/user1"

ftp> cd /etc  <- main 서버 '/etc' 디렉토리 이동
250 Directory successfully changed.

ftp> pwd   <- main 서버 현재 디렉토리 확인
257 "/etc"


ftp> ls issue*   <- main 서버 '/etc' 디렉토리에 'issue' 파일 확인
227 Entering Passive Mode (172,20,1,1,67,56).
150 Here comes the directory listing.
-rw-r--r--    1 0        0              47 Oct 23  2014 issue
-rw-r--r--    1 0        0              46 Oct 23  2014 issue.net
226 Directory send OK.

ftp> ! pwd   <- clone1 현재 디렉토리 확인
/root

ftp> ! mkdir download   <- clone1 '/download' 디렉토리 생성

ftp> lcd download   <- clone1 '/download' 디렉토리 이동
Local directory now /root/download

ftp> ! pwd   <- clone1 현재 디렉토리 확인
/root/download

ftp> ascii   <- 전송 모드 ASCII 타입으로 변경
200 Switching to ASCII mode.

ftp> get issue*   <- 'get' 명령어를 이용한 파일 다운로드 실시, 단 'get'은 '*' 옵션 사용 불가능
227 Entering Passive Mode (172,20,1,1,24,204).
550 Failed to open file.

ftp> mget issue*   <- 'mget' 명령어를 이용한 다수 파일 다운로드 실시, 'mget'은 '*' 옵션 사용 가능
mget issue? y
227 Entering Passive Mode (172,20,1,1,202,226).
150 Opening BINARY mode data connection for issue (47 bytes).
WARNING! 3 bare linefeeds received in ASCII mode
File may not have transferred correctly.
226 Transfer complete.
47 bytes received in 0.000118 secs (398.31 Kbytes/sec)


mget issue.net? y
227 Entering Passive Mode (172,20,1,1,187,184).
150 Opening BINARY mode data connection for issue.net (46 bytes).
WARNING! 2 bare linefeeds received in ASCII mode
File may not have transferred correctly.
226 Transfer complete.
46 bytes received in 0.000108 secs (425.93 Kbytes/sec)
ftp>
ftp> ! ls
issue  issue.net

 

 

 

Ex2) 비대화식 파일 다운로드

 

ftp> cd /bin   <- main 서버 '/bin' 디렉토리 이동
250 Directory successfully changed.

ftp> pwd   <- main 서버 현재 디렉토리 확인
257 "/bin"

ftp> hash   <- 파일송수신시 '#' 마크를 이용하여 전송상태 표시
Hash mark printing on (1024 bytes/hash mark).

ftp> prompt   <- 대화식 파일 송수신 해지
Interactive mode off.

ftp> mget cp mkdir   <- 'mget' 명령어를 이용하여 'cp', 'mkdir' 파일 다운로드 실시
local: cp remote: cp
227 Entering Passive Mode (172,20,1,1,131,116).
150 Opening BINARY mode data connection for cp (122872 bytes).
####################################################################################################################
226 Transfer complete.
122872 bytes received in 0.00299 secs (41094.32 Kbytes/sec)
local: mkdir remote: mkdir
227 Entering Passive Mode (172,20,1,1,212,195).
150 Opening BINARY mode data connection for mkdir (49384 bytes).
################################################
226 Transfer complete.
49384 bytes received in 0.00169 secs (29169.52 Kbytes/sec)
ftp>
ftp> ! ls
cp  issue  issue.net  mkdir


ftp> quit
221 Goodbye.

[root@clone1 /root]# ls /root/download

cp  issue  issue.net  mkdir

 

 

 

 

4. 익명계정(anonymous) 접속 방법

 

[root@clone1 /root]# ftp
ftp> open main
Connected to main (172.20.1.1).
220 (vsFTPd 2.2.2)
Name (main:root): anonymous
331 Please specify the password.
Password:   <- 패스워드 입력 없이, 그냥 엔터 실시
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
ftp> ls
227 Entering Passive Mode (172,20,1,1,36,245).
150 Here comes the directory listing.
drwxr-xr-x    2 0        0            4096 Jul 24  2015 pub 
226 Directory send OK.
ftp>
ftp> cd /etc
550 Failed to change directory.   <- 익명계정으로 접속하면 보안상 익명계정 디렉토리 이외에 다른 디렉토리로 이동 불가능
ftp>
ftp> quit
221 Goodbye.
[root@clone1 /root]#

 

 

 

 

[참고] FTP 클라이언트 유형

 

FTP 접속은 위의 실습처럼 리눅스에서만 접속되는 것이 아니라, 윈도우 탐색기, 윈도우 CMD, 알-FTP, 파일질라를 통해서 접속 가능하다.

 

Posted by 김정우 강사(카카오톡 : kim10322)
,


Q