본문으로 건너뛰기
🛠️ToolsShed

SFTP Commands Reference

SSH를 통한 파일 전송을 위한 완전한 SFTP 명령 치트시트입니다.

27 명령어

sftp연결

Connect to SFTP server

문법:

sftp [user@]host[:path]

예시:

sftp user@example.com
sftp -P연결

Connect on a specific port

문법:

sftp -P <port> user@host

예시:

sftp -P 2222 user@example.com
sftp -i연결

Connect using identity/key file

문법:

sftp -i <keyfile> user@host

예시:

sftp -i ~/.ssh/id_rsa user@example.com
exit / quit / bye연결

Close the SFTP connection

문법:

exit

예시:

exit
ls네비게이션

List remote directory contents

문법:

ls [-l] [path]

예시:

ls -l /home/user
lls네비게이션

List local directory contents

문법:

lls [path]

예시:

lls ~/Downloads
pwd네비게이션

Print remote working directory

문법:

pwd

예시:

pwd
lpwd네비게이션

Print local working directory

문법:

lpwd

예시:

lpwd
cd네비게이션

Change remote directory

문법:

cd <path>

예시:

cd /var/www/html
lcd네비게이션

Change local directory

문법:

lcd <path>

예시:

lcd ~/projects
get전송

Download file from remote to local

문법:

get <remote> [local]

예시:

get backup.tar.gz
get -r전송

Download directory recursively

문법:

get -r <dir> [local]

예시:

get -r /remote/dir ./local
put전송

Upload file from local to remote

문법:

put <local> [remote]

예시:

put index.html /var/www/
put -r전송

Upload directory recursively

문법:

put -r <dir> [remote]

예시:

put -r ./dist /var/www/
mget전송

Download multiple files matching pattern

문법:

mget <pattern>

예시:

mget *.log
mput전송

Upload multiple files matching pattern

문법:

mput <pattern>

예시:

mput *.jpg
reget전송

Resume an interrupted download

문법:

reget <remote> <local>

예시:

reget bigfile.zip bigfile.zip
rm관리

Remove remote file

문법:

rm <path>

예시:

rm /tmp/old.log
rmdir관리

Remove remote directory

문법:

rmdir <path>

예시:

rmdir /tmp/olddir
mkdir관리

Create remote directory

문법:

mkdir <path>

예시:

mkdir /var/www/uploads
rename관리

Rename or move remote file

문법:

rename <old> <new>

예시:

rename old.txt new.txt
chmod관리

Change remote file permissions

문법:

chmod <mode> <path>

예시:

chmod 644 index.html
chown관리

Change remote file owner

문법:

chown <owner> <path>

예시:

chown www-data file.php
df정보

Show remote disk usage

문법:

df [-h]

예시:

df -h
stat정보

Show file attributes

문법:

stat <path>

예시:

stat /etc/passwd
version정보

Show SFTP protocol version

문법:

version

예시:

version
help정보

Show all available commands

문법:

help

예시:

help

이 도구 소개

SFTP(SSH 파일 전송 프로토콜)는 SSH 연결을 통해 컴퓨터 간에 파일을 안전하게 전송하는 방법입니다. FTP와 같은 오래된 프로토콜과 달리 SFTP는 엔드투엔드 암호화를 제공하여 데이터 탈취로부터 보호하고 인증 자격증명의 기밀성을 보장합니다. 이 참조 가이드는 가장 일반적으로 사용되는 SFTP 명령어를 한 곳에 모아 개발자, 시스템 관리자, DevOps 엔지니어가 구문을 외우지 않고 파일 작업을 쉽게 실행할 수 있도록 합니다.

명령줄에서 SFTP를 사용하여 원격 서버에 연결하고, 디렉토리 구조를 탐색하고, 파일을 업로드 및 다운로드하고, 권한을 관리할 수 있습니다—모두 보안 터널을 통해. 애플리케이션을 배포하든, 구성을 백업하든, 로그를 전송하든, get, put, ls, cd와 같은 SFTP 명령어는 워크플로의 기본 도구입니다. 치트시트 형식을 사용하면 여러 문서 페이지 간에 전환하지 않고도 명령어 구문과 옵션을 빠르게 찾을 수 있습니다.

이 도구는 보안과 신뢰성이 중요한 프로덕션 환경에서 원격 서버를 다루는 모든 사람에게 가장 유용합니다. DevOps 팀, 시스템 관리자, 개발자는 SFTP 구문에 대한 빠른 참조를 가짐으로써 이점을 얻습니다. 특히 파일 전송 문제를 해결하거나 안전한 파일 처리를 배워야 하는 새로운 팀원을 온보딩할 때 유용합니다.

자주 묻는 질문

코드 구현

import subprocess
import os

def sftp_connect(host: str, user: str, port: int = 22, key_file: str = None) -> list[str]:
    """Build an sftp command to connect to a remote host."""
    cmd = ["sftp"]
    if port != 22:
        cmd.extend(["-P", str(port)])
    if key_file:
        cmd.extend(["-i", key_file])
    cmd.append(f"{user}@{host}")
    return cmd

def sftp_batch_commands(local_dir: str, remote_dir: str, files: list[str]) -> str:
    """Generate SFTP batch file commands for uploading multiple files."""
    lines = [f"cd {remote_dir}", f"lcd {local_dir}"]
    for f in files:
        lines.append(f"put {f}")
    lines.append("bye")
    return "\n".join(lines)

# Example: create a batch file for SFTP upload
batch = sftp_batch_commands("/local/uploads", "/remote/data", ["a.csv", "b.csv"])
print("SFTP batch commands:")
print(batch)

# Write to batch file and run
with open("/tmp/sftp_batch.txt", "w") as bfile:
    bfile.write(batch)
cmd = sftp_connect("example.com", "myuser") + ["-b", "/tmp/sftp_batch.txt"]
print("\nCommand:", " ".join(cmd))
# subprocess.run(cmd)  # Uncomment to actually run

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.