Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

sftp

Transfer files interactively over SSH, like a secure FTP client.

Niveau
RHCSA-examen
Groep
SSH en werken op afstand
Root nodig
Nee
Pakket
openssh-clients

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

sftp opens a session with a prompt sftp>. You browse the remote folders, download with get and upload with put. It uses the SSH login and encryption, so no extra server is needed: the SSH server has an SFTP subsystem.

Commands with an l in front work on your local side: lls, lcd, lpwd.

Zo schrijf je het

sftp [OPTIONS] [USER@]HOST[:PATH]
sftp [OPTIONS] -b BATCHFILE [USER@]HOST

Belangrijkste delen

Commands at the sftp> prompt

ls [path] / lls [path]
List remote / local files.
cd path / lcd path
Change the remote / local folder.
pwd / lpwd
Show the remote / local folder.
get remote [local]
Download a file. get -r downloads a folder.
put local [remote]
Upload a file. put -r uploads a folder.
mget pattern / mput pattern
Download / upload many files (wildcards).
reget / reput
Continue an interrupted download / upload.
mkdir path / rmdir path
Make / remove a remote folder.
rm file
Remove a remote file.
rename old new
Rename a remote file.
chmod mode file / chown uid file / chgrp gid file
Change remote permissions or owner.
ln -s target link
Make a remote link.
df [-h]
Show free space on the remote side.
! command
Run a local shell command.
help / ?
Show the commands.
bye / exit / quit
Leave sftp.

Opties 24

Meest gebruikt

-P port
The SSH port of the server.
-i file
Use this private key.
-b file
Run the commands of a batch file (no prompt). -b - reads them from stdin.
-r
Copy folders recursively with get and put.
-a
Resume interrupted transfers.
-p
Keep times and permissions.
-J destination
Connect through a jump host.
-l limit
Limit the bandwidth in Kbit/s.
-C
Compress the data.
-q
Quiet: no progress meter.
-N
Turn off quiet mode (for batch mode).
-v
Verbose debug output.
-f
Flush files to disk right after the transfer.
-o option
Pass an ssh option.
-F file
Use another ssh client config file.
-c cipher
Choose the cipher.
-B size
Buffer size for transfers.
-R n
Number of requests at the same time (speed).
-S program
Use this program instead of ssh.
-s subsystem
Use another SFTP subsystem or server program.
-D command
Connect to a local sftp-server directly (testing).
-X option
SFTP protocol options.
-4 / -6
Use only IPv4 / only IPv6.
-A
Forward the ssh-agent.

Voorbeelden 11

$ als gewone gebruiker# als root (of met sudo)

  1. 1Open a session

    sftp student@server2
    sftp> ls
    sftp> get /etc/os-release
    sftp> bye

    get downloads to your current local folder.

  2. 2Upload a file

    sftp student@server2
    sftp> cd /tmp
    sftp> put report.pdf

    The file goes into the remote folder you are in.

  3. 3Change the local folder first

    sftp student@server2
    sftp> lcd ~/Downloads
    sftp> get backup.tar.gz

    lcd = local cd.

  4. 4Download a whole folder

    sftp -r student@server2:/var/www/html ./site-copy

    -r with a path downloads recursively without a prompt.

  5. 5Use another port

    sftp -P 2222 admin@files.example.com

    Capital P, like scp.

  6. 6Run commands from a batch file (automation)

    cat upload.batch
    cd /incoming
    put daily-report.csv
    bye
    sftp -b upload.batch partner@sftp.partner.com

    Typical for sending files to a partner company every night.

  7. 7Resume a big download

    sftp -a student@server2:/srv/iso/rhel-10.iso .

    Continues where the last try stopped.

  8. 8Check the free space on the server

    sftp student@server2
    sftp> df -h

    Before you upload a big file.

  9. 9Upload many files at once

    sftp student@server2
    sftp> mput *.csv

    Wildcards work on your local file names.

  10. 10Use a jump host

    sftp -J admin@bastion.example.com admin@10.10.0.20

    Reach a file server in a private network.

  11. 11Run a local command without leaving

    sftp student@server2
    sftp> !ls -lh

    ! runs the command on your computer.

Let op

  • A server can allow SFTP only (chroot), so ssh login does not work but sftp does — that is on purpose.
  • put and get overwrite files with the same name without asking.

Tips om te onthouden

  • get = download, put = upload, l = local (lcd, lls, lpwd), bye = leave.

Volledige handleiding

Deze pagina legt het commando uit in eenvoudige woorden. De originele handleiding heeft elk detail.

In je terminal: man sftp