Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> 電腦軟體教學 >> 伺服器技術 >> FTP 伺服器

FTP 指令完整速查表:從入門到精通

編輯:FTP 伺服器

熟練掌握 FTP 指令能大幅提升遠端檔案管理效率,無論是撰寫自動化腳本、排除連線故障,或是在無圖形介面的伺服器環境操作,都是必備技能。本文整理標準 FTP 內部指令,附參數說明與實用範例,方便隨時查閱。

啟動參數

ftp [-v] [-d] [-i] [-n] [-g] [主機名]

  • -v:顯示伺服器所有回應訊息
  • -n:取消自動登入(不讀取 .netrc)
  • -d:啟用除錯模式
  • -g:停用檔名萬用字元擴展

核心內部指令分類速查

連線與認證

指令功能範例
open host [port]建立 FTP 連線,可指定埠號open ftp.example.com 2121
user username [password] [account]提供登入身分user alice secret123
account [password]補充存取資源所需帳號密碼account respass
bye / quit結束 FTP 工作階段bye
close / disconnect中斷連線但保留 FTP 提示符close

傳輸模式設定

指令功能
ascii設定 ASCII 模式(文字檔預設)
binary / bin / image設定二進位模式(程式、壓縮檔、圖片必須)
type [type-name]指定傳輸類型,如 type binary
mode [modename]設定傳輸模式(預設 stream)
struct [struct-name]設定檔案結構(預設 stream)
tenex設定 TENEX 機型傳輸類型

目錄與檔案操作

指令功能範例
cd remote-dir切換遠端目錄cd /var/www/html
cdup返回遠端上層目錄cdup
pwd顯示遠端目前目錄pwd
dir [remote-dir] [local-file]列出遠端目錄詳細資訊,可存成本地檔dir /backup list.txt
ls [remote-dir] [local-file]簡易列出遠端目錄ls *.log
nlist [remote-dir] [local-file]列出純檔名清單nlist /data files.txt
mkdir dir-name建立遠端目錄mkdir images
rmdir dir-name刪除遠端空目錄rmdir old
delete remote-file刪除單一遠端檔案delete test.tmp
mdelete remote-files刪除多個遠端檔案mdelete *.bak
rename from to更名遠端檔案rename index.html index_old.html
chmod mode file-name變更遠端檔案權限chmod 755 script.sh
size file-name查詢遠端檔案大小size data.zip
modtime file-name查詢遠端檔案修改時間modtime report.pdf

檔案上傳/下載

指令功能範例
get remote-file [local-file]下載單一檔案get server.log local.log
mget remote-files下載多個檔案(搭配 prompt 關閉提示)mget *.csv
put local-file [remote-file]上傳單一檔案put local.zip backup.zip
mput local-files上傳多個檔案mput *.jpg
append local-file [remote-file]續傳/附加上傳至遠端檔案append big.log
reget remote-file [local-file]斷點續傳下載reget large.iso
restart marker指定續傳位移點restart 102400

本地端操作

指令功能範例
lcd [dir]切換本地工作目錄lcd d:\ftp\upload
!cmd [args]執行本地 Shell 指令!dir *.zip
!ls列出本地目錄(Unix-like)!ls -l

進階與特殊功能

指令功能
passive進入被動模式(PASV)
sendport啟用 PORT 指令(主動模式)
proxy ftp-cmd在次要控制連線執行指令(伺服器間傳檔)
quote arg1 arg2...直接送出原始 FTP 指令至伺服器
site arg1 arg2...送出 SITE 指令(伺服器專用擴充)
macdef macro-name定義巨集,空白行結束
$ macro-name [args]執行已定義巨集
prompt切換多檔傳輸互動提示
glob切換檔名萬用字元擴展
hash每傳 1024 Bytes 顯示 # 進度
bell指令完成發出嗶聲
verbose切換詳細回報模式
debug [value]設定除錯等級(0 關閉)
trace啟用封包追蹤
runique本地檔名唯一化(避免覆蓋)
sunique遠端檔名唯一化
umask [newmask]設定伺服器預設 umask
idle [seconds]設定伺服器閒置逾時
system顯示伺服器作業系統類型
status顯示目前 FTP 狀態
help [cmd]顯示指令說明
rhelp [cmd-name]請求遠端伺服器說明
rstatus [file-name]查詢遠端狀態/檔案狀態
reset清除回應佇列

實用技巧備忘

  • 二進位模式是大前提:上傳/下載非純文字檔前,務必先輸入 bin,否則檔案將損毀。
  • 關閉互動提示:批量傳輸前執行 prompt,避免逐檔確認。
  • 善用巨集:重複性操作可用 macdef 封裝,搭配 $ 呼叫。
  • 斷點續傳:restart + reget/append 組合,大檔傳輸更安心。
  • 查詢伺服器支援指令:quote HELP 或 rhelp 可列出遠端實際支援指令集。

將此速查表加入書籤,下次操作命令列 FTP 時即能得心應手。若需自動化腳本,建議搭配 -n 參數並以 user、pass 指令處理認證,再以 mput/mget 完成批量作業。

Copyright © Windows教程網 All Rights Reserved