SFTP Commands Reference
SSH를 통한 파일 전송을 위한 완전한 SFTP 명령 치트시트입니다.
27 명령어
sftp연결Connect to SFTP server
문법:
sftp [user@]host[:path]예시:
sftp user@example.comsftp -P연결Connect on a specific port
문법:
sftp -P <port> user@host예시:
sftp -P 2222 user@example.comsftp -i연결Connect using identity/key file
문법:
sftp -i <keyfile> user@host예시:
sftp -i ~/.ssh/id_rsa user@example.comexit / quit / bye연결Close the SFTP connection
문법:
exit예시:
exitls네비게이션List remote directory contents
문법:
ls [-l] [path]예시:
ls -l /home/userlls네비게이션List local directory contents
문법:
lls [path]예시:
lls ~/Downloadspwd네비게이션Print remote working directory
문법:
pwd예시:
pwdlpwd네비게이션Print local working directory
문법:
lpwd예시:
lpwdcd네비게이션Change remote directory
문법:
cd <path>예시:
cd /var/www/htmllcd네비게이션Change local directory
문법:
lcd <path>예시:
lcd ~/projectsget전송Download file from remote to local
문법:
get <remote> [local]예시:
get backup.tar.gzget -r전송Download directory recursively
문법:
get -r <dir> [local]예시:
get -r /remote/dir ./localput전송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 *.logmput전송Upload multiple files matching pattern
문법:
mput <pattern>예시:
mput *.jpgreget전송Resume an interrupted download
문법:
reget <remote> <local>예시:
reget bigfile.zip bigfile.ziprm관리Remove remote file
문법:
rm <path>예시:
rm /tmp/old.logrmdir관리Remove remote directory
문법:
rmdir <path>예시:
rmdir /tmp/olddirmkdir관리Create remote directory
문법:
mkdir <path>예시:
mkdir /var/www/uploadsrename관리Rename or move remote file
문법:
rename <old> <new>예시:
rename old.txt new.txtchmod관리Change remote file permissions
문법:
chmod <mode> <path>예시:
chmod 644 index.htmlchown관리Change remote file owner
문법:
chown <owner> <path>예시:
chown www-data file.phpdf정보Show remote disk usage
문법:
df [-h]예시:
df -hstat정보Show file attributes
문법:
stat <path>예시:
stat /etc/passwdversion정보Show SFTP protocol version
문법:
version예시:
versionhelp정보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 runComments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.