FTP 是網管與開發者高頻工具。熟練內部指令可大幅提升操作效率。本文整理標準 FTP 指令集(DOS/UNIX 通用)。
ftp [-v] [-d] [-i] [-n] [-g] [hostname]-v 顯示伺服器回應 | -d 除錯模式 | -i 關閉多檔互動提示 | -n 禁用 .netrc 自動登入 | -g 關閉檔名全域擴展。
(中括號 [] 表可選參數)
| 指令 | 語法 | 功能說明 |
|---|---|---|
| ! | ! [cmd [args]] | 執行本地 Shell,exit 回 FTP。例:!ls *.zip |
| $ | $ macro-name [args] | 執行巨集定義 |
| account | account [password] | 登入後提供存取資源補充密碼 |
| append | append local-file [remote-file] | 本地檔案追加上傳,遠端檔名省略則同本地 |
| ascii | ascii | 設定 ASCII 傳輸模式 |
| bell | bell | 每指令完成嗶一聲 |
| bin / binary / image | bin | 設定二進位傳輸模式 |
| bye / quit | bye | 結束 FTP 會話 |
| case | case | mget 時將遠端大寫檔名轉小寫 |
| cd | cd remote-dir | 切換遠端目錄 |
| cdup | cdup | 進入遠端父目錄 |
| chmod | chmod mode file-name | 設定遠端檔案權限 (如 chmod 777 a.out) |
| close / disconnect | close | 中斷當前 FTP 會話 |
| cr | cr | ASCII 模式下 CR+LF → LF 轉換 |
| delete | delete remote-file | 刪除遠端檔案 |
| debug | debug [debug-value] | 設定除錯等級 (0 關閉)。例:debug 3 |
| dir | dir [remote-dir] [local-file] | 詳細列表遠端目錄,可存本地檔 |
| form | form format | 設定檔案傳輸格式 (預設 file) |
| get / recv | get remote-file [local-file] | 下載單一檔案 |
| glob | glob | 啟用 mget/mput/mdelete 檔名擴展 (對應 -g) |
| hash | hash | 每傳 1024 位元組顯示 # 進度指示 |
| help / ? | help [cmd] | 顯示指令說明。例:help get |
| idle | idle [seconds] | 設定遠端伺服器閒置逾時秒數 |
| lcd | lcd [dir] | 切換本地工作目錄 |
| ls | ls [remote-dir] [local-file] | 簡略列表遠端目錄,可存本地檔 |
| macdef | macdef macro-name | 定義巨集,空行結束 |
| mdelete | mdelete [remote-files] | 批量刪除遠端檔案 |
| mdir | mdir remote-files local-file | 多檔詳細列表存本地。例:mdir *.o *.zip outfile |
| mget | mget remote-files | 下載多個遠端檔案 |
| mkdir | mkdir dir-name | 建立遠端目錄 |
| mls | mls remote-files local-file | 多檔簡略列表存本地 (同 nlist 但可指定多檔) |
| mode | mode [modename] | 設定傳輸模式 (預設 stream) |
| modtime | modtime file-name | 顯示遠端檔案最後修改時間 |
| mput | mput local-files | 上傳多個本地檔案 |
| newer | newer file-name | 遠端檔案較新才重傳 |
| nlist | nlist [remote-dir] [local-file] | 遠端檔名清單存本地 |
| nmap | nmap [inpattern outpattern] | 檔名映射機制 (非 UNIX 伺服器適用)。例:nmap $1.$2.$3 $1.$2 |
| ntrans | ntrans [inchars [outchars]] | 檔名字元轉換。例:ntrans 1 R 將 1→R |
| open | open host [port] | 建立指定 FTP 連線,可指定埠 |
| passive | passive | 進入被動傳輸模式 (PASV) |
| prompt | prompt | 切換多檔傳輸互動確認提示 |
| proxy | proxy ftp-cmd | 次要連線執行 FTP 指令,實現雙伺服器直傳 (首指令必為 open) |
| put / send | put local-file [remote-file] | 上傳單一檔案 |
| pwd | pwd | 顯示遠端當前工作目錄 |
| quote | quote arg1, arg2... | 原樣發送參數給伺服器。例:quote SYST |
| reget | reget remote-file [local-file] | 斷點續傳下載 (本地檔存在時從中斷處續傳) |
| rhelp | rhelp [cmd-name] | 請求遠端伺服器幫助 |
| rstatus | rstatus [file-name] | 顯示遠端伺服器/檔案狀態 |
| rename | rename [from] [to] | 重命名遠端檔案 |
| reset | reset | 清除回應佇列 |
| restart | restart marker | 從標記處重新 get/put。例:restart 130 |
| rmdir | rmdir dir-name | 刪除遠端目錄 |
| runique | runique | 本地檔名唯一化 (衝突加 .1 .2...) |
| sendport | sendport | 啟用 PORT 指令 (主動模式) |
| site | site arg1, arg2... | 發送 SITE 指令給伺服器。例:site idle 7200 |
| size | size file-name | 顯示遠端檔案大小 |
| status | status | 顯示目前 FTP 狀態 |
| struct | struct [struct-name] | 設定檔案傳輸結構 (預設 stream) |
| sunique | sunique | 遠端檔名唯一化 (對應 runique) |
| system | system | 顯示遠端伺服器作業系統類型 |
| tenex | tenex | 設定 TENEX 機器專用傳輸類型 |
| tick | tick | 設定傳輸位元組計數器 |
| trace | trace | 啟用封包追蹤 |
| type | type [type-name] | 設定傳輸類型 (預設 ascii)。例:type binary |
| umask | umask [newmask] | 設定遠端伺服器預設 umask。例:umask 3 |
| user | user user-name [password] [account] | 宣告身份。例:user anonymous my@email |
| verbose | verbose | 啟用詳細回報 (同 -v),預設開啟 |
收藏此表,FTP 操作查無不備。