LFCA 54 ๐ง Interactive Transfer โ sftp
The previous chapter covered scp โ the one-shot copy where the source and destination are given on the command line, the transfer runs, and the command exits. That model works when you know exactly which file you want and where it should go. It breaks down when you need to look around first. The sftp command is the answer: it opens an interactive session over SSH, gives you a prompt, and lets you browse, upload, download, rename, and delete files on the remote host using a small command language that resembles the classic FTP client. Because it runs over SSH, the session is encrypted, the authentication is the same key or password you already use, and the ~/.ssh/config, the ssh-agent, and the jump hosts all apply. This chapter covers what sftp is, the interactive commands, the batch mode, the resume and mirror features, the way it compares to scp and rsync, and the habits that make interactive transfers safe.
Key point: The sftp user@host opens the interactive session, and the prompt is sftp>. The commands are the ls, the cd, the pwd, the get, the put, the mget, the mput, the mkdir, the rmdir, the rm, the rename, the chmod, the bye (or exit or quit). The local side is reached through the lcd, the lls, and the lpwd โ the l prefix means local. The -b option runs a batch file, and the -r option makes the get and the put recursive. The get and the put support the -a (the resume) and the -r (the recursive) flags. The sftp is the interactive’s alternative to the scp‘s one-shot, and the rsync‘s is the delta’s. The sftp is the modern’s replacement for the scp‘s deprecation in the OpenSSH 9.0.
Why the sftp matters
The sftp is the interactive’s, and the interactive’s is the browse’s.
The sftp‘s case. The sftp‘s case is the “I need to look around first” โ the unknown’s directory’s, the browse’s, the explore’s. The scp‘s is the “I know the exact path” โ the one-shot’s, the script’s. The two are the pair, and the pair is the design’s.
The sftp‘s protocol. The sftp‘s protocol is the SSH’s subsystem’s, and the subsystem’s is the SSH’s. The sftp‘s is the SFTP’s protocol, and the protocol’s is the SSH’s transport’s. The two are the pair, and the pair is the security’s.
The sftp‘s the FTP’s similarity. The sftp‘s is the FTP’s command’s, and the FTP’s is the familiar’s. The sftp‘s is the ls‘s, the cd‘s, the get‘s, the put‘s โ the same’s as the FTP’s. The two are the pair, and the pair is the design’s.
Why the sftp matters for the interactive’s. The sftp matters for the interactive’s, and the interactive’s is the browse’s. The sftp‘s is the prompt’s, and the prompt’s is the session’s. The two are the pair, and the pair is the design’s.
Why the sftp matters for the batch’s. The sftp matters for the batch’s, and the batch’s is the script’s. The sftp -b file‘s is the batch’s, and the batch’s is the automation’s. The two are the pair, and the pair is the efficiency’s.
Why the sftp matters for the resume’s. The sftp matters for the resume’s, and the resume’s is the large’s. The get -a‘s is the resume’s, and the resume’s is the interrupted’s. The two are the pair, and the pair is the design’s.
Why the sftp matters for the recursive’s. The sftp matters for the recursive’s, and the recursive’s is the directory’s. The get -r‘s is the recursive’s, and the recursive’s is the whole’s. The two are the pair, and the pair is the design’s.
Why the sftp matters for the modern’s. The sftp matters for the modern’s, and the modern’s is the OpenSSH 9.0’s. The scp‘s is the deprecated’s, and the sftp‘s is the replacement’s. The two are the pair, and the pair is the transition’s.
Why the
sftpis the interactive’s. Thesftpis the interactive’s, and the interactive’s is the prompt’s. Thesftp‘s is the session’s, and the session’s is the browse’s. The two are the pair, and the pair is the design’s.
The sftp‘s basic usage
The sftp user@host is the basic’s, and the basic’s is the session’s.
sftp user@example.com
# Connected to example.com.
# sftp>
The sftp user@example.com is the basic’s, and the basic’s is the session’s. The Connected to example.com. is the confirmation’s, and the confirmation’s is the success’s. The sftp> is the prompt’s, and the prompt’s is the session’s. The two are the pair, and the pair is the design’s.
Why the sftp‘s basic matters. The sftp‘s basic is the session’s, and the session’s is the interactive’s. The sftp‘s is the prompt’s, and the prompt’s is the command’s. The two are the pair, and the pair is the design’s.
The sftp‘s the port’s. The sftp -P 2222 user@example.com is the port’s, and the port’s is the uppercase’s.
sftp -P 2222 user@example.com
The sftp -P 2222 is the port’s, and the port’s is the uppercase’s. The two are the pair, and the pair is the design’s.
Why the sftp‘s the port’s matters. The sftp‘s the port’s is the uppercase’s, and the uppercase’s is the scp‘s the same’s. The -P‘s is the port’s, and the -p‘s is the preserve’s. The two are the pair, and the pair is the distinction’s.
The sftp‘s the key’s. The sftp -i ~/.ssh/id_ed25519 user@example.com is the key’s, and the key’s is the specific’s.
sftp -i ~/.ssh/id_ed25519 user@example.com
The sftp -i ~/.ssh/id_ed25519 is the key’s, and the key’s is the specific’s. The two are the pair, and the pair is the design’s.
Why the sftp‘s the key’s matters. The sftp‘s the key’s is the specific’s, and the specific’s is the multi-key’s. The -i‘s is the key’s, and the key’s is the authentication’s. The two are the pair, and the pair is the design’s.
The sftp‘s the config’s. The sftp example is the alias’s, and the alias’s is the ~/.ssh/config‘s.
sftp example
# The ~/.ssh/config's is the applied's.
The sftp example is the alias’s, and the alias’s is the ~/.ssh/config‘s. The two are the pair, and the pair is the convenience’s.
Why the sftp‘s the config’s matters. The sftp‘s the config’s is the alias’s, and the alias’s is the convenient’s. The ~/.ssh/config‘s is the applied’s, and the applied’s is the seamless’s. The two are the pair, and the pair is the design’s.
The sftp‘s the URL’s. The sftp://user@example.com/path is the URL’s, and the URL’s is the modern’s.
sftp sftp://user@example.com/tmp/
The sftp sftp://user@example.com/tmp/ is the URL’s, and the URL’s is the modern’s. The two are the pair, and the pair is the design’s.
Why the sftp‘s the URL’s matters. The sftp‘s the URL’s is the modern’s, and the modern’s is the convenient’s. The sftp://‘s is the protocol’s, and the protocol’s is the specific’s. The two are the pair, and the pair is the design’s.
The sftp‘s the remote’s commands
The sftp‘s the remote’s commands are the ls, the cd, the pwd, the mkdir, the rmdir, the rm, the rename, the chmod, the stat‘s.
The ls‘s. The ls is the list’s, and the list’s is the remote’s.
sftp> ls
# file.txt project logs
The ls is the list’s, and the list’s is the remote’s. The two are the pair, and the pair is the browse’s.
Why the ls‘s matters. The ls‘s is the list’s, and the list’s is the browse’s. The ls -la‘s is the detail’s, and the detail’s is the permission’s. The two are the pair, and the pair is the design’s.
The cd‘s. The cd is the change’s, and the change’s is the directory’s.
sftp> cd /tmp
sftp> pwd
# Remote working directory: /tmp
The cd /tmp is the change’s, and the change’s is the directory’s. The pwd is the current’s, and the current’s is the remote’s. The two are the pair, and the pair is the design’s.
Why the cd‘s matters. The cd‘s is the change’s, and the change’s is the directory’s. The cd‘s is the navigation’s, and the navigation’s is the browse’s. The two are the pair, and the pair is the design’s.
The pwd‘s. The pwd is the current’s, and the current’s is the remote’s.
sftp> pwd
# Remote working directory: /home/user
The pwd is the current’s, and the current’s is the remote’s. The two are the pair, and the pair is the design’s.
Why the pwd‘s matters. The pwd‘s is the current’s, and the current’s is the remote’s. The pwd‘s is the orientation’s, and the orientation’s is the browse’s. The two are the pair, and the pair is the design’s.
The mkdir‘s. The mkdir is the create’s, and the create’s is the directory’s.
sftp> mkdir new_dir
The mkdir new_dir is the create’s, and the create’s is the directory’s. The two are the pair, and the pair is the design’s.
Why the mkdir‘s matters. The mkdir‘s is the create’s, and the create’s is the directory’s. The mkdir‘s is the remote’s, and the remote’s is the design’s. The two are the pair, and the pair is the design’s.
The rmdir‘s. The rmdir is the remove’s, and the remove’s is the empty’s.
sftp> rmdir old_dir
The rmdir old_dir is the remove’s, and the remove’s is the empty’s. The two are the pair, and the pair is the design’s.
Why the rmdir‘s matters. The rmdir‘s is the remove’s, and the remove’s is the empty’s. The rmdir‘s is the safe’s, and the safe’s is the empty’s. The two are the pair, and the pair is the design’s.
The rm‘s. The rm is the remove’s, and the remove’s is the file’s.
sftp> rm file.txt
The rm file.txt is the remove’s, and the remove’s is the file’s. The two are the pair, and the pair is the design’s.
Why the rm‘s matters. The rm‘s is the remove’s, and the remove’s is the file’s. The rm‘s is the dangerous’s, and the dangerous’s is the no-undo’s. The two are the pair, and the pair is the design’s.
The rename‘s. The rename is the move’s, and the move’s is the rename’s.
sftp> rename old.txt new.txt
The rename old.txt new.txt is the move’s, and the move’s is the rename’s. The two are the pair, and the pair is the design’s.
Why the rename‘s matters. The rename‘s is the move’s, and the move’s is the rename’s. The rename‘s is the remote’s, and the remote’s is the design’s. The two are the pair, and the pair is the design’s.
The chmod‘s. The chmod is the mode’s, and the mode’s is the permission’s.
sftp> chmod 600 file.txt
The chmod 600 file.txt is the mode’s, and the mode’s is the permission’s. The two are the pair, and the pair is the design’s.
Why the chmod‘s matters. The chmod‘s is the mode’s, and the mode’s is the permission’s. The chmod‘s is the remote’s, and the remote’s is the design’s. The two are the pair, and the pair is the design’s.
The stat‘s. The stat is the info’s, and the info’s is the detail’s.
sftp> stat file.txt
The stat file.txt is the info’s, and the info’s is the detail’s. The two are the pair, and the pair is the design’s.
Why the stat‘s matters. The stat‘s is the info’s, and the info’s is the detail’s. The stat‘s is the permission’s and the size’s, and the size’s is the design’s. The two are the pair, and the pair is the design’s.
The sftp‘s the local’s commands
The sftp‘s the local’s commands are the lls, the lcd, the lpwd, the lmkdir‘s. The l prefix’s is the local’s.
The lls‘s. The lls is the local’s list’s, and the list’s is the local’s.
sftp> lls
# local_file.txt local_project/
The lls is the local’s list’s, and the list’s is the local’s. The two are the pair, and the pair is the browse’s.
Why the lls‘s matters. The lls‘s is the local’s list’s, and the list’s is the local’s. The lls‘s is the l prefix’s, and the prefix’s is the distinction’s. The two are the pair, and the pair is the design’s.
The lcd‘s. The lcd is the local’s change’s, and the change’s is the local’s.
sftp> lcd /tmp
sftp> lpwd
# Local working directory: /tmp
The lcd /tmp is the local’s change’s, and the change’s is the local’s. The lpwd is the local’s current’s, and the current’s is the local’s. The two are the pair, and the pair is the design’s.
Why the lcd‘s matters. The lcd‘s is the local’s change’s, and the change’s is the local’s. The lcd‘s is the navigation’s, and the navigation’s is the local’s. The two are the pair, and the pair is the design’s.
The lpwd‘s. The lpwd is the local’s current’s, and the current’s is the local’s.
sftp> lpwd
# Local working directory: /home/user
The lpwd is the local’s current’s, and the current’s is the local’s. The two are the pair, and the pair is the design’s.
Why the lpwd‘s matters. The lpwd‘s is the local’s current’s, and the current’s is the local’s. The lpwd‘s is the orientation’s, and the orientation’s is the local’s. The two are the pair, and the pair is the design’s.
The lmkdir‘s. The lmkdir is the local’s create’s, and the create’s is the directory’s.
sftp> lmkdir new_local_dir
The lmkdir new_local_dir is the local’s create’s, and the create’s is the directory’s. The two are the pair, and the pair is the design’s.
Why the lmkdir‘s matters. The lmkdir‘s is the local’s create’s, and the create’s is the directory’s. The lmkdir‘s is the l prefix’s, and the prefix’s is the distinction’s. The two are the pair, and the pair is the design’s.
The !‘s. The !command is the local’s shell’s, and the shell’s is the local’s.
sftp> !ls
# The local's shell's is the executed's.
The !ls is the local’s shell’s, and the shell’s is the local’s. The two are the pair, and the pair is the design’s.
Why the !‘s matters. The !‘s is the local’s shell’s, and the shell’s is the local’s. The !‘s is the escape’s, and the escape’s is the convenient’s. The two are the pair, and the pair is the design’s.
The sftp‘s the transfer’s commands
The sftp‘s the transfer’s commands are the get, the put, the mget, the mput‘s.
The get‘s. The get is the download’s, and the download’s is the remote’s-to-local’s.
sftp> get remote.txt
# Fetching /home/user/remote.txt to remote.txt
# remote.txt 100% 1024 1.2MB/s 00:00
The get remote.txt is the download’s, and the download’s is the remote’s-to-local’s. The two are the pair, and the pair is the design’s.
Why the get‘s matters. The get‘s is the download’s, and the download’s is the remote’s. The get‘s is the single’s, and the single’s is the common’s. The two are the pair, and the pair is the design’s.
The put‘s. The put is the upload’s, and the upload’s is the local’s-to-remote’s.
sftp> put local.txt
# Uploading local.txt to /home/user/local.txt
# local.txt 100% 1024 1.2MB/s 00:00
The put local.txt is the upload’s, and the upload’s is the local’s-to-remote’s. The two are the pair, and the pair is the design’s.
Why the put‘s matters. The put‘s is the upload’s, and the upload’s is the local’s. The put‘s is the single’s, and the single’s is the common’s. The two are the pair, and the pair is the design’s.
The mget‘s. The mget is the multiple’s download’s, and the download’s is the pattern’s.
sftp> mget *.txt
# Fetching /home/user/a.txt to a.txt
# Fetching /home/user/b.txt to b.txt
The mget *.txt is the multiple’s, and the multiple’s is the pattern’s. The two are the pair, and the pair is the design’s.
Why the mget‘s matters. The mget‘s is the multiple’s, and the multiple’s is the pattern’s. The mget‘s is the glob’s, and the glob’s is the convenient’s. The two are the pair, and the pair is the design’s.
The mput‘s. The mput is the multiple’s upload’s, and the upload’s is the pattern’s.
sftp> mput *.txt
# Uploading a.txt to /home/user/a.txt
# Uploading b.txt to /home/user/b.txt
The mput *.txt is the multiple’s, and the multiple’s is the pattern’s. The two are the pair, and the pair is the design’s.
Why the mput‘s matters. The mput‘s is the multiple’s, and the multiple’s is the pattern’s. The mput‘s is the glob’s, and the glob’s is the convenient’s. The two are the pair, and the pair is the design’s.
The get‘s the -r‘s. The get -r is the recursive’s, and the recursive’s is the directory’s.
sftp> get -r project/
# Fetching /home/user/project/ to project
The get -r project/ is the recursive’s, and the recursive’s is the directory’s. The two are the pair, and the pair is the design’s.
Why the get -r‘s matters. The get -r‘s is the recursive’s, and the recursive’s is the directory’s. The get -r‘s is the whole’s, and the whole’s is the tree’s. The two are the pair, and the pair is the design’s.
The put‘s the -r‘s. The put -r is the recursive’s, and the recursive’s is the directory’s.
sftp> put -r project/
# Uploading project/ to /home/user/project/
The put -r project/ is the recursive’s, and the recursive’s is the directory’s. The two are the pair, and the pair is the design’s.
Why the put -r‘s matters. The put -r‘s is the recursive’s, and the recursive’s is the directory’s. The put -r‘s is the whole’s, and the whole’s is the tree’s. The two are the pair, and the pair is the design’s.
The get‘s the -a‘s. The get -a is the resume’s, and the resume’s is the interrupted’s.
sftp> get -a large.iso
# Resuming the transfer's.
The get -a large.iso is the resume’s, and the resume’s is the interrupted’s. The two are the pair, and the pair is the design’s.
Why the get -a‘s matters. The get -a‘s is the resume’s, and the resume’s is the large’s. The get -a‘s is the interrupted’s, and the interrupted’s is the efficient’s. The two are the pair, and the pair is the design’s.
The put‘s the -a‘s. The put -a is the resume’s, and the resume’s is the interrupted’s.
sftp> put -a large.iso
# Resuming the transfer's.
The put -a large.iso is the resume’s, and the resume’s is the interrupted’s. The two are the pair, and the pair is the design’s.
Why the put -a‘s matters. The put -a‘s is the resume’s, and the resume’s is the large’s. The put -a‘s is the interrupted’s, and the interrupted’s is the efficient’s. The two are the pair, and the pair is the design’s.
The sftp‘s the exit’s commands
The sftp‘s the exit’s commands are the bye, the exit, the quit‘s.
The bye‘s. The bye is the exit’s, and the exit’s is the session’s.
sftp> bye
# The session's is the closed's.
The bye is the exit’s, and the exit’s is the session’s. The two are the pair, and the pair is the design’s.
Why the bye‘s matters. The bye‘s is the exit’s, and the exit’s is the session’s. The bye‘s is the common’s, and the common’s is the familiar’s. The two are the pair, and the pair is the design’s.
The exit‘s. The exit is the exit’s, and the exit’s is the session’s.
sftp> exit
# The session's is the closed's.
The exit is the exit’s, and the exit’s is the session’s. The two are the pair, and the pair is the design’s.
Why the exit‘s matters. The exit‘s is the exit’s, and the exit’s is the session’s. The exit‘s is the shell’s, and the shell’s is the familiar’s. The two are the pair, and the pair is the design’s.
The quit‘s. The quit is the exit’s, and the exit’s is the session’s.
sftp> quit
# The session's is the closed's.
The quit is the exit’s, and the exit’s is the session’s. The two are the pair, and the pair is the design’s.
Why the quit‘s matters. The quit‘s is the exit’s, and the exit’s is the session’s. The quit‘s is the FTP’s, and the FTP’s is the familiar’s. The two are the pair, and the pair is the design’s.
The Ctrl+D‘s. The Ctrl+D is the EOF’s, and the EOF’s is the exit’s.
sftp> # The Ctrl+D's is the exit's.
The Ctrl+D is the EOF’s, and the EOF’s is the exit’s. The two are the pair, and the pair is the design’s.
Why the Ctrl+D‘s matters. The Ctrl+D‘s is the EOF’s, and the EOF’s is the exit’s. The Ctrl+D‘s is the shell’s, and the shell’s is the familiar’s. The two are the pair, and the pair is the design’s.
The sftp‘s the batch’s mode
The sftp‘s the batch’s mode is the -b file‘s, and the -b‘s is the script’s.
sftp -b commands.txt user@example.com
The sftp -b commands.txt user@example.com is the batch’s, and the batch’s is the script’s. The commands.txt is the file’s, and the file’s is the commands’s. The two are the pair, and the pair is the automation’s.
Why the sftp‘s the batch’s matters. The sftp‘s the batch’s is the script’s, and the script’s is the automation’s. The -b‘s is the file’s, and the file’s is the commands’s. The two are the pair, and the pair is the efficiency’s.
The batch’s the commands.txt‘s. The commands.txt is the file’s, and the file’s is the commands’s.
# commands.txt
cd /tmp
put local.txt
get remote.txt
bye
The cd /tmp, the put local.txt, the get remote.txt, the bye are the commands’s, and the commands’s is the file’s. The two are the pair, and the pair is the automation’s.
Why the commands.txt‘s matters. The commands.txt‘s is the commands’s, and the commands’s is the file’s. The commands.txt‘s is the batch’s, and the batch’s is the script’s. The two are the pair, and the pair is the design’s.
The batch’s the -b‘s and the -‘s. The sftp -b - user@example.com is the stdin’s, and the stdin’s is the pipe’s.
echo -e "cd /tmp\nput local.txt\nbye" | sftp -b - user@example.com
The sftp -b - user@example.com is the stdin’s, and the stdin’s is the pipe’s. The two are the pair, and the pair is the automation’s.
Why the sftp -b -‘s matters. The sftp -b -‘s is the stdin’s, and the stdin’s is the pipe’s. The sftp -b -‘s is the convenient’s, and the convenient’s is the heredoc’s. The two are the pair, and the pair is the design’s.
The batch’s the non-interactive’s. The sftp‘s the batch’s is the non-interactive’s, and the non-interactive’s is the script’s.
sftp -b commands.txt user@example.com
# The non-interactive's is the script's.
The sftp -b commands.txt user@example.com is the non-interactive’s, and the non-interactive’s is the script’s. The two are the pair, and the pair is the automation’s.
Why the batch’s the non-interactive’s matters. The batch’s the non-interactive’s is the script’s, and the script’s is the automation’s. The -b‘s is the file’s, and the file’s is the commands’s. The two are the pair, and the pair is the design’s.
The batch’s the error’s. The sftp‘s the batch’s is the error’s, and the error’s is the abort’s.
sftp -b commands.txt user@example.com
# The error's is the abort's.
The sftp -b commands.txt is the error’s, and the error’s is the abort’s. The two are the pair, and the pair is the safety’s.
Why the batch’s the error’s matters. The batch’s the error’s is the abort’s, and the abort’s is the safety’s. The -b‘s is the abort’s, and the abort’s is the fail-fast’s. The two are the pair, and the pair is the design’s.
The sftp‘s versus the scp‘s and the rsync‘s
The sftp‘s versus the scp‘s and the rsync‘s is the comparison’s.
The sftp‘s the interactive’s. The sftp‘s the interactive’s is the browse’s, and the browse’s is the explore’s.
sftp user@example.com
# The interactive's is the browse's.
The sftp user@example.com is the interactive’s, and the interactive’s is the browse’s. The two are the pair, and the pair is the design’s.
Why the sftp‘s the interactive’s matters. The sftp‘s the interactive’s is the browse’s, and the browse’s is the explore’s. The sftp‘s is the look-around’s, and the look-around’s is the flexible’s. The two are the pair, and the pair is the design’s.
The scp‘s the one-shot’s. The scp‘s the one-shot’s is the known’s, and the known’s is the script’s.
scp file.txt user@example.com:/tmp/
# The one-shot's is the known's.
The scp file.txt is the one-shot’s, and the one-shot’s is the known’s. The two are the pair, and the pair is the design’s.
Why the scp‘s the one-shot’s matters. The scp‘s the one-shot’s is the known’s, and the known’s is the script’s. The scp‘s is the simple’s, and the simple’s is the fast’s. The two are the pair, and the pair is the design’s.
The rsync‘s the delta’s. The rsync‘s the delta’s is the efficient’s, and the efficient’s is the repeated’s.
rsync -avz project/ user@example.com:/tmp/project/
# The delta's is the efficient's.
The rsync -avz project/ is the delta’s, and the delta’s is the efficient’s. The two are the pair, and the pair is the design’s.
Why the rsync‘s the delta’s matters. The rsync‘s the delta’s is the efficient’s, and the efficient’s is the repeated’s. The rsync‘s is the mirror’s, and the mirror’s is the sync’s. The two are the pair, and the pair is the design’s.
The sftp‘s the modern’s. The sftp‘s the modern’s is the OpenSSH 9.0’s, and the OpenSSH 9.0’s is the scp‘s the deprecation’s.
# The sftp's is the OpenSSH 9.0's recommendation's.
The sftp‘s is the modern’s, and the modern’s is the OpenSSH 9.0’s. The two are the pair, and the pair is the transition’s.
Why the sftp‘s the modern’s matters. The sftp‘s the modern’s is the OpenSSH 9.0’s, and the OpenSSH 9.0’s is the scp‘s the deprecation’s. The sftp‘s is the recommendation’s, and the recommendation’s is the design’s. The two are the pair, and the pair is the transition’s.
The three’s the comparison’s. The sftp‘s is the interactive’s, the scp‘s is the one-shot’s, the rsync‘s is the delta’s. The three are the comparison’s, and the comparison’s is the design’s.
sftp โ the interactive's, the browse's
scp โ the one-shot's, the simple's
rsync โ the delta's, the efficient's
The sftp, the scp, the rsync are the three, and the three are the comparison’s. The two are the pair, and the pair is the design’s.
Why the three’s the comparison’s matters. The three’s the comparison’s is the design’s, and the design’s is the choice’s. The sftp‘s is the interactive’s, the scp‘s is the one-shot’s, the rsync‘s is the delta’s. The two are the pair, and the pair is the design’s.
Complete Example Session
# ============================================
# PART 1: THE BASIC SFTP
# ============================================
sftp user@example.com
# Connected to example.com.
# sftp>
# ============================================
# PART 2: THE REMOTE'S COMMANDS
# ============================================
sftp> ls
# file.txt project logs
sftp> cd /tmp
sftp> pwd
# Remote working directory: /tmp
sftp> ls -la
# drwxr-xr-x ... .
# ============================================
# PART 3: THE TRANSFER'S
# ============================================
sftp> get remote.txt
# Fetching /tmp/remote.txt to remote.txt
sftp> put local.txt
# Uploading local.txt to /tmp/local.txt
sftp> mget *.txt
sftp> mput *.log
# ============================================
# PART 4: THE RECURSIVE'S
# ============================================
sftp> get -r project/
sftp> put -r new_project/
# ============================================
# PART 5: THE RESUME'S
# ============================================
sftp> get -a large.iso
sftp> put -a large.iso
# ============================================
# PART 6: THE LOCAL'S
# ============================================
sftp> lls
sftp> lcd /tmp
sftp> lpwd
# Local working directory: /tmp
sftp> !ls
# The local's shell's is the executed's.
# ============================================
# PART 7: THE REMOTE'S MANAGEMENT'S
# ============================================
sftp> mkdir new_dir
sftp> rmdir old_dir
sftp> rm file.txt
sftp> rename old.txt new.txt
sftp> chmod 600 file.txt
sftp> stat file.txt
# ============================================
# PART 8: THE EXIT'S
# ============================================
sftp> bye
# ============================================
# PART 9: THE BATCH'S
# ============================================
# commands.txt
# cd /tmp
# put local.txt
# get remote.txt
# bye
sftp -b commands.txt user@example.com
# The batch's is the executed's.
# ============================================
# PART 10: WHAT NOT TO DO
# ============================================
# Don't use the -p for the port
sftp -p 2222 user@example.com # โ the -p is not the port's // โ ๏ธ
# Don't forget the l prefix for the local's
sftp> cd /tmp # โ the remote's // โ ๏ธ
sftp> lcd /tmp # โ
the local's
# Don't use the mget without the glob's
sftp> mget file.txt # โ the single's // โ ๏ธ
# Don't forget the bye
# The session's is the open's. // โ ๏ธ
# Don't use the sftp for the one-shot's
# The scp's is the simpler's. // โ ๏ธ
# Don't use the sftp for the delta's
# The rsync's is the efficient's. // โ ๏ธ
The ten parts cover the basic sftp, the remote’s commands, the transfer’s, the recursive’s, the resume’s, the local’s, the remote’s management’s, the exit’s, the batch’s, and the anti-patterns.
Quick Reference
The Remote’s Commands
| Command | Purpose |
|---|---|
ls | The list’s |
cd | The change’s |
pwd | The current’s |
mkdir | The create’s |
rmdir | The remove’s (the empty’s) |
rm | The remove’s (the file’s) |
rename | The move’s |
chmod | The mode’s |
stat | The info’s |
The Local’s Commands
| Command | Purpose |
|---|---|
lls | The local’s list’s |
lcd | The local’s change’s |
lpwd | The local’s current’s |
lmkdir | The local’s create’s |
!cmd | The local’s shell’s |
The Transfer’s Commands
| Command | Purpose |
|---|---|
get | The download’s |
put | The upload’s |
mget | The multiple’s download’s |
mput | The multiple’s upload’s |
get -r | The recursive’s |
put -r | The recursive’s |
get -a | The resume’s |
put -a | The resume’s |
The Exit’s Commands
| Command | Purpose |
|---|---|
bye | The exit’s |
exit | The exit’s |
quit | The exit’s |
Ctrl+D | The EOF’s |
The Command-Line’s Options
| Option | Purpose |
|---|---|
-P PORT | The port’s |
-i KEY | The key’s |
-b FILE | The batch’s |
-r | The recursive’s |
-a | The resume’s |
-v | The verbose’s |
The sftp‘s vs the scp‘s vs the rsync‘s
| Tool | Use |
|---|---|
sftp | The interactive’s |
scp | The one-shot’s |
rsync | The delta’s |
Best Practices
โ Do This:
# Use the sftp for the interactive's
sftp user@example.com # โ
# Use the l prefix for the local's
sftp> lcd /tmp && sftp> lpwd # โ
# Use the get -r for the directory's
sftp> get -r project/ # โ
# Use the get -a for the resume's
sftp> get -a large.iso # โ
# Use the batch's mode for the script's
sftp -b commands.txt user@example.com # โ
# Use the bye to exit
sftp> bye # โ
# Use the ~/.ssh/config for the alias
sftp example # โ
โ Don’t Do This:
# Don't use the -p for the port
sftp -p 2222 user@example.com # โ the -P's is the port's // โ ๏ธ
# Don't forget the l prefix for the local's
sftp> cd /tmp # โ the remote's // โ ๏ธ
# Don't use the mget without the glob's
sftp> mget file.txt # โ the single's // โ ๏ธ
# Don't forget the bye
# The session's is the open's. // โ ๏ธ
# Don't use the sftp for the one-shot's
# The scp's is the simpler's. // โ ๏ธ
# Don't use the sftp for the delta's
# The rsync's is the efficient's. // โ ๏ธ
Common Pitfalls
| Pitfall | Problem | Solution |
|---|---|---|
The -p for the port | The wrong’s option’s | The -P |
The missing l prefix | The remote’s | The lcd, the lls, the lpwd |
The mget without the glob | The single’s | The mget *.txt |
The forgotten bye | The open’s session’s | The bye |
The sftp for the one-shot’s | The slow’s | The scp |
The sftp for the delta’s | The whole’s | The rsync |
The cd for the local’s | The remote’s | The lcd |
The get‘s the no-resume’s | The restart’s | The -a |
Real-World Examples
1. The basic session
sftp user@example.com
2. The remote’s browse
sftp> ls && sftp> cd /tmp && sftp> pwd
3. The download
sftp> get remote.txt
4. The upload
sftp> put local.txt
5. The recursive
sftp> get -r project/
6. The resume
sftp> get -a large.iso
7. The local’s
sftp> lcd /tmp && sftp> lpwd
8. The remote’s management’s
sftp> mkdir new_dir && sftp> rename old.txt new.txt
9. The batch’s
sftp -b commands.txt user@example.com
10. The exit’s
sftp> bye
Visual: The sftp‘s Session
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ sftp user@example.com โ
โ โ โ
โ โ The SSH's connection's โ
โ โผ โ
โ Connected to example.com. โ
โ sftp> โ
โ โ โ
โ โโโ The remote's commands (the ls, the cd)โ
โ โโโ The transfer's (the get, the put) โ
โ โโโ The local's (the lls, the lcd) โ
โ โโโ The exit's (the bye) โ
โ โ
โ The prompt's is the interactive's. โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Visual: The sftp‘s Commands’s the l Prefix’s
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ THE REMOTE'S (the no prefix's) โ
โ ls, cd, pwd, mkdir, rm โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ THE LOCAL'S (the l prefix's) โ
โ lls, lcd, lpwd, lmkdir โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ THE TRANSFER'S โ
โ get (the remote's โ the local's) โ
โ put (the local's โ the remote's) โ
โ โ
โ The l prefix's is the local's. โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Visual: The sftp‘s the transfer’s
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ THE REMOTE'S โ
โ /tmp/remote.txt โ
โ โ โ
โ โ get remote.txt โ
โ โผ โ
โ THE LOCAL'S โ
โ ./remote.txt โ
โ โ โ
โ โ put local.txt โ
โ โผ โ
โ THE REMOTE'S โ
โ /tmp/local.txt โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Visual: The sftp‘s vs the scp‘s vs the rsync‘s
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ THE SFTP'S โ
โ The interactive's, the browse's โ
โ The prompt's, the session's โ
โ The one-file's, the explore's โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ THE SCP'S โ
โ The one-shot's, the known's โ
โ The command's, the script's โ
โ The simple's, the fast's โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ THE RSYNC'S โ
โ The delta's, the efficient's โ
โ The repeated's, the mirror's โ
โ The large's, the sync's โ
โ โ
โ The three are the choice's. โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Visual: The sftp‘s the batch’s
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ commands.txt โ
โ cd /tmp โ
โ put local.txt โ
โ get remote.txt โ
โ bye โ
โ โ
โ sftp -b commands.txt user@example.com โ
โ โ โ
โ โ The commands's are the executed's. โ
โ โผ โ
โ The session's is the closed's. โ
โ โ
โ The batch's is the non-interactive's. โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Summary
| Item | Value |
|---|---|
| The basic | sftp user@host |
| The prompt | sftp> |
| The remote’s | The ls, the cd, the pwd, the mkdir |
| The local’s | The lls, the lcd, the lpwd |
| The download’s | The get |
| The upload’s | The put |
| The multiple’s | The mget, the mput |
| The recursive’s | The get -r, the put -r |
| The resume’s | The get -a, the put -a |
| The exit’s | The bye, the exit, the quit |
| The batch’s | The -b file |
| The port’s | The -P (the uppercase’s) |
Key takeaways:
- The
sftp user@hostopens the interactive session, and the prompt issftp>โ the session is the SSH’s transport’s, and the encryption is the default’s - The remote’s commands are the
ls, thecd, thepwd, themkdir, thermdir, therm, therename, thechmod, thestatโ the same’s as the FTP’s - The
lprefix’s is the local’s โ thells, thelcd, thelpwd, thelmkdirare the local’s, and the!cmdis the local’s shell’s - The
getis the download’s, and theputis the upload’s โ themgetand themputare the multiple’s, and the-ris the recursive’s - The
-ais the resume’s โ theget -aand theput -aresume the interrupted’s transfer’s - The exit’s commands are the
bye, theexit, thequitโ theCtrl+Dis the EOF’s - The
-b fileis the batch’s mode โ thesftp -b commands.txt user@hostruns the file’s commands’s, and the-b -is the stdin’s - The
-P(the uppercase’s) is the port’s โ the-pis not the port’s, and thescp‘s the same’s - The
~/.ssh/config‘s and thessh-agent‘s are the applied’s โ thesftp example‘s is the alias’s, and the passphrase’s is the cached’s - The
sftp‘s is the interactive’s, thescp‘s is the one-shot’s, and thersync‘s is the delta’s โ the three are the choice’s, and the choice’s is the design’s
Remember: The sftp‘s is the interactive’s transfer’s, and the prompt’s is the session’s. The remote’s commands are the same’s as the FTP’s, and the l prefix’s is the local’s. The get‘s is the download’s, and the put‘s is the upload’s. The -b‘s is the batch’s, and the -a‘s is the resume’s. The sftp‘s is the modern’s, and the modern’s is the OpenSSH 9.0’s.
Stop using slow, ad-bloated tool sites! ๐คฎ
๐ Search “KandZ Tools” on Google to use many professional utilities for free.
KandZ.me is the ultimate minimalist hub for:
โ
Finance (Mortgage, Interest, Inflation)
โ
Tech (Base64, JSON, Dev Suite, IP)
โ
Health (BMI, BMR, TDEE)
โ
Productivity (Timer, Workspace, QR)
โก๏ธ Fast & Private
๐ No data leaves your device
๐ 100% Free
๐ Use it now: https://tools.kandz.me
๐ Bookmark itโyouโll need it later!