scp보다 좀 더 기능이 많은 sftp도 있습니다.

sftp도 ssh를 기반으로 실행되며 sftp로 remote server로 접속 후 get 또는 put 명령으로 파일일 내려받거나 올릴 수 있습니다. shell(interactive command) 명령도 사용할 수 있습니다.

 

먼저 sftp로 remote server에 접속합니다.

$ sftp tongchun@10.10.0.118

tongchun@10.10.0.118's password:

Connected to tongchun@10.10.0.118.

sftp>

 

 

 

sftp로 접속하면 sftp 프롬프트 창이 생성됩니다.

sftp 프롬프트 창에서 ls -al, cd, mkdir 등의 interactive command를 실행할 수 있습니다.

사용할 수 있는 interactive command 명령은 아래 링크에서 확인할 수 있습니다.

https://www.mankier.com/1/sftp#Interactive_Commands

 

sftp - secure file transfer program - man page | ManKier

Batch mode reads a series of commands from an input batchfile instead of stdin. Since it lacks user interaction it should be used in conjunction with non-interactive authentication to obviate the need to enter a password at connection time (see sshd(8) and

www.mankier.com

가장 많이 사용하는 명령은 cd, mkdir, pwd, get, put, exit 정도입니다.

sftp로 remote server 접속 후 cd로 파일을 내려받거나 올리고자 하는 경로로 이동합니다.

그리고 get으로 파일을 다운 받거나, put으로 파일을 올릴 수 있습니다.

sftp 프롬프트 창을 종료하려면 exit 명령을 실행하면 됩니다.

 

위에서 접속한 10.10.0.118 서버에서 pwd 명령으로 디렉토리 경로를 확인해 봅니다.

sftp> pwd

Remote working directory: /home/tongchun

 

 

pwd 명령을 실행하면 remote server의 디렉토리 경로를 확인할 수 있습니다.

lpwd 명령을 실행하면 현재의 로컬 PC의 경로를 확인할 수 있습니다.

sftp> lpwd

Local working directory: /Users/tongchunkim

 

 

이번엔 파일 리스트를 확인해 봅니다.

sftp> ls -l

drwxrwxr-x 5 tongchun tongchun 39 Apr 17 05:59 go

-rw-rw-r-- 1 tongchun tongchun 127928770 Apr 11 22:09 go1.12.4.linux-amd64.tar.gz

-rw-r--r-- 1 root root 6140 Nov 12 2015 mysql-community-release-el7-5.noarch.rpm

 

 

 

go1.12.4.linux-amd64.tar.gz 파일을 다운받아 보겠습니다. 명령어는 get 입니다.

sftp> get go1.12.4.linux-amd64.tar.gz

Fetching /home/tongchun/go1.12.4.linux-amd64.tar.gz to go1.12.4.linux-amd64.tar.gz

/home/tongchun/go1.12.4.linux-amd64.tar.gz 100% 122MB 57.0MB/s 00:02

 

 

 

잘 받아졌는지 로컬 PC의 파일 리스트를 확인해 봅니다. 로컬 PC에 명령을 보내려면 remote server에서 사용한 명령 앞에 l를 붙여줍니다.

sftp> lls -l

total 263904

drwxr-xr-x 3 tongchunkim staff 96 7 30 2018 AndroidStudioProjects

drwx------@ 4 tongchunkim staff 128 12 12 2017 Applications

drwx------+ 6 tongchunkim staff 192 4 22 19:08 Desktop

drwx------+ 31 tongchunkim staff 992 3 18 10:00 Documents

drwx------+ 75 tongchunkim staff 2400 4 25 16:54 Downloads

drwx------@ 10 tongchunkim staff 320 1 28 19:18 Dropbox

drwx------@ 83 tongchunkim staff 2656 4 6 14:16 Library

drwx------+ 3 tongchunkim staff 96 12 12 2017 Movies

-rw-r--r-- 1 tongchunkim staff 127928770 4 26 14:44 go1.12.4.linux-amd64.tar.gz

-rw-r--r-- 1 tongchunkim staff 9180 1 12 2018 jmeter.log

drwxr-xr-x 14 tongchunkim staff 448 2 6 2018 macaronRamlProject

-rw-r--r-- 1 tongchunkim staff 26484 7 29 2018 package-lock.json

drwxr-xr-x 3 tongchunkim staff 96 9 16 2018 snakepit

 

 

go1.12.4.linux-amd64.tar.gz이 보이네요.

 

이번에는 파일을 업로드해 보겠습니다. jmeter.log 파일을 올려봅시다. 파일을 올리는 명령은 put입니다.

sftp> put jmeter.log

Uploading jmeter.log to /home/tongchun/jmeter.log

jmeter.log 100% 9180 268.9KB/s 00:00

 

 

 

파일이 잘 올라갔는지 확인해 봅니다.

sftp> ls -l

drwxrwxr-x 5 tongchun tongchun 39 Apr 17 05:59 go

-rw-rw-r-- 1 tongchun tongchun 127928770 Apr 11 22:09 go1.12.4.linux-amd64.tar.gz

-rw-r--r-- 1 tongchun tongchun 9180 Apr 26 01:49 jmeter.log

-rw-r--r-- 1 root root 6140 Nov 12 2015 mysql-community-release-el7-5.noarch.rpm

 

 

 

파일이 잘 올라가네요.

sftp를 종료할 때는 exit 입니다.

다른 interactive command를 확인하면 더 유용하게 사용할 수 있을 것 같습니다.

'program > linux-common' 카테고리의 다른 글

rcp remote 상에서의 파일 전송  (0) 2021.07.06
rlogin  (0) 2021.05.12
리눅스 환경 변수 설정  (0) 2021.03.27
linux 패키지 관리 프로그램 snap apt  (0) 2021.03.26
ubuntu 에서 github-desktop 설치하기  (0) 2021.03.26

+ Recent posts