sftp Command
sftp 명령어
- Secure File Transfer Program 의 약자로,
SFTP(SSH File Transfer Protocol) 기반의 Command-Line Interface Client Program 이다.
- sftp
는 리눅스 유틸리티, SFTP는 프로토콜임을 명심하자.
* SFTP (SSH File Transfer Protocol) (URL)
※ Notation
- 본 포스트에서 사용하는 표기법은 아래와 같다:
<name>
- 필수적으로 명시해야 하는 옵션값[name]
- 선택적으로 명시할 수 있는(생략 가능한) 옵션값
sftp Synopsis
sftp [-46AaCfNpqrv] [-B <buffer_size>] [-b <batchfile>] [-c <cipher>]
[-D <sftp_server_command>] [-F <ssh_config>] [-i <identity_file>]
[-J <destination>] [-l <limit>] [-o <ssh_option>] [-P <port>]
[-R <num_requests>] [-S <program>] [-s <subsystem | sftp_server>]
[-X <sftp_option>] <destination>
Options | Description |
-4 | - sftp가 IPv4 주소 체계를 사용하도록 강제한다. |
-6 | - sftp가 IPv6 주소 체계를 사용하도록 강제한다. |
-A | - ssh-agent의 원격지 시스템으로의 포워딩을 허용한다. - 기본값은 No 이다. |
-a | - 기존 파일의 일부 또는 전체 복사본을 덮어쓰지 않고 중단된 전송을 계속 시도한다. - 일부 내용이 전송되는 내용과 다른 경우, 결과 파일이 손상되었을 가능성이 높다. |
-C | - ssh 명령의 -C Flag를 통한 파일 압축을 허용한다. |
-f | - Requests that files be flushed to disk immediately after transfer - When uploading files, this feature is only enabled if the server implements the "fsync@openssh.com" extension |
-N | - Quiet Mode를 해제한다. - e.g. to override the implicit quiet mode set by the -b flag |
-p | - Preserves modification times, access times, and modes from the original files transferred |
-q | - Quiet mode - disables the progress meter as well as warning and diagnostic messages from ssh |
-r | - Recursively copy entire directories when uploading and downloading - Note that sftp does not follow symbolic links encountered in the tree traversal |
-v | - Logging Level을 상향 조정한다. |
-B <buffer_size> | - 파일을 전송할 때 사용되는 버퍼의 크기를 지정한다. - 기본값은 32,768 bytes이다. |
-b <batchfile> | - 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 and ssh-keygen for details) - A batchfile of ‘-’ may be used to indicate standard input - sftp will abort if any of the following commands fail: get, put, reget, reput, rename, ln, rm, mkdir, chdir, ls, lchdir, copy, cp, chmod, chown, chgrp, lpwd, df, symlink, lmkdir - Termination on error can be suppressed on a command by command basis by prefixing the command with a ‘-’ character (for example, -rm /tmp/blah*) - Echo of the command may be suppressed by prefixing the command with a ‘@’ character - These two prefixes may be combined in any order, for example -@ls /bsd. |
-c <cipher> | - 암호화 전송 시 사용할 암호화 알고리즘을 명시한다. |
-D <sftp_server_command> | - Connect directly to a local sftp server (rather than via ssh) - A command and arguments may be specified, for example "/path/sftp-server -el debug3" - This option may be useful in debugging the client and server |
-F <ssh_config> | - Specifies an alternative per-user configuration file for ssh - 이 옵션값은 ssh 명령에 곧바로 인계된다. |
-i <identify_file> | - 공개키 인증을 위한 Private Key를 명시한다. - 이 옵션값은 ssh 명령에 곧바로 인계된다. |
-J <destination> | - Connect to the target host by first making an sftp connection to the jump host described by destination and then establishing a TCP forwarding to the ultimate destination from there. - Multiple jump hops may be specified separated by comma characters - This is a shortcut to specify a ProxyJump configuration directive - This option is directly passed to ssh |
-l <limit> | - 대역폭을 <limit> Kbit/s 로 제한한다. |
-o <ssh_option> | * 하단에 상세히 서술함. |
-P <port> | - 연결하고자 하는 원격지 호스트의 포트번호를 명시한다. |
-R <num_requests> | - Specify how many requests may be outstanding at any one time - Increasing this may slightly improve file transfer speed but will increase memory usage - The default is 64 outstanding requests. |
-S <program> | - Encrypted Connection 상에서 실행할 프로그램 이름을 명시한다. |
-s <subsystem | sftp_server> | - Specifies the SSH2 subsystem or the path for an sftp server on the remote host - A path is useful when the remote sshd does not have an sftp subsystem configured |
-X <sftp_option> | - SFTP protocol behaviour를 명시한다. nrequests=value - Concurrent SFTP가 동시에 읽고 쓸 수 있는 요청 개수를 지정한다. - 기본값은 64이다. buffer=value - Single SFTP의 최대 버퍼 크기를 KB 단위로 지정한다. - 기본값은 32KB이다. |
<destination> | - destination은 아래 형태로 명시되어야 한다: - [user@]host[:path] - sftp://[user@]host[:port][/path] |
* -o <ssh_option>
- Can be used to pass options to ssh in the format used in ssh_config(5)
- This is useful for specifying options for which there is no separate sftp command-line flag
- For example, to specify an alternate port use: sftp -oPort=24
- For full details of the options listed below, and their possible values, see ssh_config
- AddressFamily
- any (default)
- inet
- inet6
- BatchMode
- yes
- no (default)
- BindAddress
- BindInterface
- CanonicalDomains
- CanonicalizeFallbackLocal
- CanonicalizeHostname
- CanonicalizeMaxDots
- CanonicalizePermittedCNAMEs
- CASignatureAlgorithms
- CertificateFile
- CheckHostIP
- Ciphers
- Compression
- ConnectionAttempts
- ConnectTimeout
- ControlMaster
- ControlPath
- ControlPersist
- GlobalKnownHostsFile
- GSSAPIAuthentication
- GSSAPIDelegateCredentials
- HashKnownHosts
- Host
- HostbasedAcceptedAlgorithms
- HostbasedAuthentication
- HostKeyAlgorithms
- HostKeyAlias
- Hostname
- IdentitiesOnly
- IdentityAgent
- IdentityFile
- IPQoS
- KbdInteractiveAuthentication
- KbdInteractiveDevices
- KexAlgorithms
- KnownHostsCommand
- LogLevel
- MACs
- NoHostAuthenticationForLocalhost
- NumberOfPasswordPrompts
- PasswordAuthentication
- PKCS11Provider
- Port
- PreferredAuthentications
- ProxyCommand
- ProxyJump
- PubkeyAcceptedAlgorithms
- PubkeyAuthentication
- RekeyLimit
- RequiredRSASize
- SendEnv
- ServerAliveInterval
- ServerAliveCountMax
- SetEnv
- StrictHostKeyChecking
- TCPKeepAlive
- UpdateHostKeys
- User
- UserKnownHostsFile
- VerifyHostKeyDNS
Interactive Commands
- sftp Connection을 성공적으로 수립한 후,
아래와 같은 명령어들을 Prompt(stfp>
)에서 수행할 수 있다.
Interactive Commands | Description |
help | - Display help text |
bye | - Quit sftp |
exit | - Quit sftp |
cd [path] | - Change remote directory to [path] - If [path] is not specified, then change directory to the on the session started in |
chgrp [-h] <grp> <path> | - Change group of file <path> to <grp> - <path> may contain glob characters and may match multiple files - <grp> must be a numeric GID - If the -h flag is specified, then symlinks will not be followed |
chmod [-h] <mode> <path> | - Change permissions of file <path> to <mode> - <path> may contain glob characters and may match multiple files - If the -h flag is specified, then symlinks will not be followed |
chown [-h] <own> <path> | - Change owner of file <path> to <own> - <path> may contain glob characters and may match multiple files - <own> must be a numeric UID - If the -h flag is specified, then symlinks will not be followed |
copy <oldpath> <newpath> | - Copy remote file from <oldpath> to <newpath> |
cp <oldpath> <newpath> | - Alias to copy command |
df [-hi] [path] | - Display usage information for the filesystem holding the current directory (or [path] if specified) - If the -h flag is specified, the capacity information will be displayed using "human-readable" suffixs - The -i flag requests display of inode information in addition to capacity information |
get [-afpR] <remote-path> [local-path] | - Retrieve the <remote-path> and store it on the local machine - If the local path name is not specified, it is given the same name it has on the remote machine - <remote-path> may contain glob characters and may match multiple files - If it does and [local-path] is specified, then [local-path] must specify a directory |
lcd [path] | - Change local directory to [path] - If [path] is not specified, then change directory to tha local use's home directory |
lls [ls-options [path]] | - Display local directory listing of either [path] or current directory if [path] is not specified - [ls-options] may contain any flags supported by the local system's ls command - [path] may contain glob characters and may match multiple files |
lmkdir <path> | - Create local directory specified by <path> |
ln [-s] <oldpath> <newpath> | - Create a link from <oldpath> to <newpath> - If the -s flag is specified the created link is a symbolic link, Otherwise it is a hard link |
lpwd | - Print local working directory |
ls [-1afhlnrSt] [path] | - Display a remote directory listing of either [path] or the current directory if [path] is not specified - [path] may contain glob characters and may match multiple files |
lumask <umask> | - Set local umask to <umask> |
mkdir <path> | - Create remote directory specified by <path> |
progress | - Toggle display of progress meter - Show Percentage of Copied Data |
put [-afpR] <local-path> [remote-path] | - Upload <local-path> and store it on the remote machine - If the remote path name is not specified, it is given the same name it has on the local machine - <local-path> may contain glob characters and may match multiple files - If it does and [remote-path] is specified, then [remote-path] must specify a directory |
pwd | - Display remote working directory |
reget [-fpR] <remote-path> [local-path] | - Resume download of <remote-path> - Equivalent to get with the -a flag set |
reput [-fpR] <local-path> [remote-path] | - Resume upload of <local-path> - Equivalent to put with the -a flag set |
rename <oldpath> <newpath> | - Rename remote file from <oldpath> to <newpath> |
rm <path> | - Delete remote file specified by <path> |
rmdir <path> | - Remove remote directory specified by <path> |
symlink <oldpath> <newpath> | - <oldpath>에 대한 Symbolic Link를 <newpath>에 생성한다. |
version | - SFTP 프로토콜 버전을 출력한다. |
!<command> | - Local Shell에서 <command> 명령을 수행한다. |
! | - Local Shell을 닫는다. |
? | - help 명령과 동일 |
sftp Exit Codes
Exit Codes | Description |
0 | - 성공 |
1 | - 파일 복사 중 알 수 없는 에러가 발생함 |
2 | - 목적지가 디렉토리가 아님 |
4 | - 호스트로의 연결 설정에 실패함 |
5 | - 호스트로의 연결이 도중에 중단됨 |
6 | - 지정한 파일이 존재하지 않음 |
7 | - 특정 파일에 접근 권한이 없음 |
8 | - 알 수 없는 에러가 발생함 - 1번 코드보다 더 광범위한 에러를 지칭한다. |
9 | - File Transfer Protocol이 맞지 않음 |
255 | - ssh 실행 중 에러가 발생함 |
Reference: opentext, SFTP, URL, 2023년 8월 16일 검색
Reference: die.net, sftp(1) - Linux man page, URL, 2023년 8월 16일 검색
Reference: man7.org, sftp(1) - Linux man page, URL, 2023년 8월 18일 검색
Reference: 은행연합회 IT부, SFTP시스템 운영 매뉴얼, 은행연합회, 2022년 12월