الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

sftp

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

المستوى
امتحان RHCSA
المجموعة
SSH والعمل عن بُعد
يحتاج root
لا
الحزمة
openssh-clients

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

ماذا يفعل

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.

طريقة الكتابة

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

الأجزاء الرئيسية

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.

الخيارات 24

الأكثر استخدامًا

-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.

أمثلة 11

$ مستخدم عادي# بصلاحية root (أو مع 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.

انتبه

  • 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.

نصائح للحفظ

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

الدليل الكامل

هذه الصفحة تشرح الأمر بكلمات بسيطة. الدليل الأصلي فيه كل التفاصيل.

في الطرفية: man sftp