在linux系統(tǒng)下,上傳php網(wǎng)頁到服務(wù)器,可以通過ftp的相關(guān)命令上傳。
建立FTP連接
要打開與遠(yuǎn)程系統(tǒng)的ftp連接,請(qǐng)使用ftp命令后跟遠(yuǎn)程服務(wù)器IP地址或域名:
ftp 192.168.42.77
1、 如果建立連接,將顯示確認(rèn)消息,系統(tǒng)將提示您輸入FTP用戶名,在此示例中,F(xiàn)TP用戶名為linuxidc:
220---------- Welcome to Pure-FTPd [privsep] [TLS] ---------- 220-You are user number 1 of 50 allowed. 220-Local time is now 21:35. Server port: 21. 220-This is a private system - No anonymous login 220-IPv6 connections are also welcome on this server. 220 You will be disconnected after 15 minutes of inactivity. Name (192.168.42.77:localuser): linuxidc You may see a different confirmation message depending on the FTP service running on the remote server.
2、 輸入用戶名后,系統(tǒng)將提示您輸入密碼:
Password:
如果密碼正確,遠(yuǎn)程服務(wù)器將顯示確認(rèn)消息和ftp>提示。
230 OK. Current restricted directory is / Remote system type is UNIX. Using binary mode to transfer files. ftp>
如果您訪問的FTP服務(wù)器接受匿名ftp帳戶,并且您想以匿名用戶anonymous身份登錄,請(qǐng)使用用戶名和電子郵件地址作為密碼。
常用FTP命令
許多FTP命令與您在Linux shell提示符中鍵入的命令類似或相同。
以下是一些最常見的FTP命令
help或?- 列出所有可用的FTP命令。 cd - 更改遠(yuǎn)程計(jì)算機(jī)上的目錄。 lcd - 更改本地計(jì)算機(jī)上的目錄。 ls - 列出當(dāng)前遠(yuǎn)程目錄中的文件和目錄的名稱。 mkdir - 在當(dāng)前遠(yuǎn)程目錄中創(chuàng)建一個(gè)新目錄。 pwd - 打印遠(yuǎn)程計(jì)算機(jī)上的當(dāng)前工作目錄。 delete - 刪除當(dāng)前遠(yuǎn)程目錄中的文件。 rmdir- 刪除當(dāng)前遠(yuǎn)程目錄中的目錄。 get - 將一個(gè)文件從遠(yuǎn)程復(fù)制到本地計(jì)算機(jī)。 mget - 將多個(gè)文件從遠(yuǎn)程復(fù)制到本地計(jì)算機(jī)。 put - 將一個(gè)文件從本地復(fù)制到遠(yuǎn)程計(jì)算機(jī)。mput - 將一個(gè)文件從本地復(fù)制到遠(yuǎn)程計(jì)算機(jī)。
使用FTP命令上載文件
要將文件從本地目錄上載到遠(yuǎn)程FTP服務(wù)器,請(qǐng)使用以下put命令:
put index.php
輸出應(yīng)該如下所示:
200 PORT command successful 150 Connecting to port 34583 226-File successfully transferred 226 0.849 seconds (measured here), 111.48 Kbytes per second 96936 bytes sent in 0.421 seconds (225 kbytes/s)
如果要上載不在當(dāng)前工作目錄中的文件,請(qǐng)使用該文件的絕對(duì)路徑。
要將多個(gè)文件從本地目錄上載到遠(yuǎn)程FTP服務(wù)器,請(qǐng)使用以下mput命令:
mput image1.jpg image2.jpg mput image1.jpg? y 200 PORT command successful 150 Connecting to port 41075 226-File successfully transferred 226 1.439 seconds (measured here), 102.89 Kbytes per second 151586 bytes sent in 1.07 seconds (138 kbytes/s) mput image2.jpg? y 200 PORT command successful 150 Connecting to port 40759 226-File successfully transferred 226 1.727 seconds (measured here), 111.75 Kbytes per second 197565 bytes sent in 1.39 seconds (138 kbytes/s)
上傳多個(gè)文件時(shí),系統(tǒng)將提示您確認(rèn)要上傳的每個(gè)文件。
完成上傳文件到遠(yuǎn)程FTP服務(wù)器后,用bye或關(guān)閉連接quit。