跳到主要内容

SFTP

Secure File Transfer Protocol 协议用于在系统之间安全的传输数据。

语法

sftp <username>@<remote hostname or IP address>

用法

  • sftp [email protected], Connect to SFTP
  • get example.txt, Download file. Syntax: get [-afpR] remote [local]
  • put example.txt, Upload file. Syntax: put [-afpR] local [remote]

指令

  • ?/help
  • quit, exit, bye, Quit sftp

指令 (remote)

  • cd <path>, Change remote directory to 'path'
  • pwd, Remote working directory
  • ls, Display remote directory listing
  • mkdir <path>, Create remote directory
  • rm <path>, Delete remote file
  • rmdir <path>, Remove remote directory
  • rename oldpath newpath, Rename remote file
  • mget *.txt, Download multiple files
  • reget [-fpR] remote [local], Resume download file

指令 (local)

  • lcd <path>, Change local directory to 'path'
  • lpwd, Local working directory
  • lls, Display local directory listing
  • lmkdir <path>, Create local directory
  • mput *.txt, Upload multiple files
  • reput [-fpR] local [remote], Resume upload file

文件权限

传输文件遇到异常,尝试修改文件夹权限 (如 sudo chmod 600 <path>)。

部分选项

-4, Forces sftp to use IPv4 addresses only.
-6, Forces sftp to use IPv6 addresses only.
-C, Compression enable.
-c cipher, Selects the cipher to use for encrypting the data transfers. This option is directly passed to ssh.
-f, Requests that files be flushed to disk immediately after transfer.
-i identity_file, Selects the file from which the identity (private key) for public key authentication is read.
-l limit, Limits the used bandwidth, specified in Kbit/s (限制带宽)
-p, Preserves modification times, access times, and file mode bits from the source file. (保留源文件中的修改时间、访问时间和文件模式位)
-P, port (指定端口)
-q, Quiet mode.
-R num_requests, Specify how many requests may be outstanding at any one time. Increasing this may slightly improve file transfer speed but will increase memory usage. The default is 64 outstanding requests.
-r, Recursively copy entire directories.
-v, Verbose mode. Causes sftp and ssh to print debugging messages about their progress. This is helpful in debugging connection, authentication, and configuration problems.

Resources