當前位置:首頁 » 文件傳輸 » juy250ftp
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

juy250ftp

發布時間: 2022-06-05 11:37:42

① FTP 信息代碼全解

120 Service ready in nnn minutes.
服務在NNN時間內可用
125 Data connection already open; transfer starting.
數據連接已經打開,開始傳送數據.

150 File status okay; about to open data connection.
文件狀態正確,正在打開數據連接.

200 Command okay.
命令執行正常結束.

202 Command not implemented, superfluous at this site.
命令未被執行,此站點不支持此命令.

211 System status, or system help reply.
系統狀態或系統幫助信息回應.

212 Directory status.
目錄狀態信息.

213 File status.
文件狀態信息.

214 Help message.On how to use the server or the meaning of a particular non-standard command. This reply is useful only to the human user. 幫助信息。關於如何使用本伺服器或特殊的非標准命令。此回復只對人有用。

215 NAME system type. Where NAME is an official system name from the list in the Assigned Numbers document.
NAME系統類型。

220 Service ready for new user.
新連接的用戶的服務已就緒

221 Service closing control connection.
控制連接關閉

225 Data connection open; no transfer in progress.
數據連接已打開,沒有進行中的數據傳送

226 Closing data connection. Requested file action successful (for example, file transfer or file abort).
正在關閉數據連接。請求文件動作成功結束(例如,文件傳送或終止)

227 Entering Passive Mode (h1,h2,h3,h4,p1,p2).
進入被動模式

230 User logged in, proceed. Logged out if appropriate.
用戶已登入。 如果不需要可以登出。

250 Requested file action okay, completed.
被請求文件操作成功完成

257 "PATHNAME" created.
路徑已建立

331 User name okay, need password.
用戶名存在,需要輸入密碼

332 Need account for login.
需要登陸的賬戶 西門吐血

350 Requested file action pending further information
對被請求文件的操作需要進一步更多的信息

421 Service not available, closing control connection.This may be a reply to any command if the service knows it must shut down.
服務不可用,控制連接關閉。這可能是對任何命令的回應,如果服務認為它必須關閉

425 Can`t open data connection.
打開數據連接失敗

426 Connection closed; transfer aborted.
連接關閉,傳送中止。

450 Requested file action not taken.
對被請求文件的操作未被執行

451 Requested action aborted. Local error in processing.
請求的操作中止。處理中發生本地錯誤。

452 Requested action not taken. Insufficient storage space in system.File unavailable (e.g., file busy).
請求的操作沒有被執行。 系統存儲空間不足。 文件不可用

500 Syntax error, command unrecognized. This may include errors such as command line too long.
語法錯誤,不可識別的命令。 這可能是命令行過長。

501 Syntax error in parameters or arguments.
參數錯誤導致的語法錯誤

502 Command not implemented.
命令未被執行

503 Bad sequence of commands.
命令的次序錯誤。

504 Command not implemented for that parameter.
由於參數錯誤,命令未被執行

530 Not logged in.
沒有登錄

532 Need account for storing files.
存儲文件需要賬戶信息 西門吐血

550 Requested action not taken. File unavailable (e.g., file not found, no access).
請求操作未被執行,文件不可用。

551 Requested action aborted. Page type unknown.
請求操作中止,頁面類型未知

552 Requested file action aborted. Exceeded storage allocation (for current directory or dataset).
對請求文件的操作中止。 超出存儲分配

553 Requested action not taken. File name not allowed
請求操作未被執行。 文件名不允許

這種錯誤跟http協議類似,大致是:
2開頭--成功
3開頭--許可權問題
4開頭--文件問題
5開頭--伺服器問題
對大家最有用的:
421:一般出現在連接數多,需稍後在接;
530:密碼錯誤;
550:目錄或文件已經被刪除。

② ftp伺服器問題

Permission denied拒絕訪問 當你試圖上傳一個文件到FTP站點上時,沒有許可權或者是站點太忙所致。

ftp登陸不了是很經常碰到的事,很多人常常是不加分析就發貼詢問。老實說,這樣既浪費自己時間,又浪費別人精力,還常常不能得到滿意的回答。因此每一位希望從ftp站點發現資源的朋友都有必要學會分析登陸失敗的原因,
兩個基本知識:
1 對方很可能暫時沒開ftp
2 要學會看登陸錯誤指令

所謂登陸提示,是指登陸時你與伺服器雙向交流的一些指令及狀態提示,你如果看到類似這樣的字樣,那就是了:
*** CuteFTP Pro 2.0 - build Dec 4 2001 ***

狀態:> 正在獲取列表」...
狀態:> 正在連接到 ftp 伺服器 211.*.*.*:* (ip = 211.*.*.*:*)...
狀態:> Socket 已連接。正在等候歡迎消息...
220 FTP伺服器已啟動
狀態:> 已連接。正在驗證...
命令:> USER software
331 User name okay, need password.
命令:> PASS *****
230 User logged in, proceed.
狀態:> 登錄成功。
命令:> PWD
257 "/" is current directory.

這個東西是非常重要的,請一定加以注意。

常見錯誤分析
如果見到下述字樣,並停留較長時間
狀態:> 正在連接到 ftp 伺服器 211.*.*.*:*(ip = 211.*.*.*:*)...

之後見到:
錯誤:> 無法連接到遠程伺服器。Socket 錯誤 = #10060。
狀態:> 正在等候 30 秒...

出現該種情況有兩種可能:
一為對方未開ftp或者無法連通,請與ftp管理者聯系
二則是因為埠填寫錯誤。一般默認為21,但是因為此種埠在某些網路中易引起沖突,安全性也值得商榷,故多數ftp更改了埠。如果你沒有填寫埠(ftp軟體會默認21)或者填寫錯誤,也會引起10060錯誤.

如果見到下述字樣
Thu Mar 07 11:44:56 2002 530 Sorry, no ANONYMOUS access allowed

表明該ftp不允許匿名者登陸,請與ftp管理者聯系,並取得賬號

Thu Mar 07 11:46:29 2002 USER bugdown
Thu Mar 07 11:46:30 2002 331 User name okay, need password.
Thu Mar 07 11:46:30 2002 PASS ********
Thu Mar 07 11:46:30 2002 530 Not logged in.
有兩種可能
1 賬號或者密碼輸入錯誤,被拒絕登陸。請先確定你沒有輸入錯誤(較復雜的密碼建議用復制粘貼來填寫,並注意有無空格),然後與ftp管理者聯系以確認你的賬號沒有過期。目前大部分的ftp都會定期更改密碼,所以此宗錯誤是最常見的。
2 用了花生殼等動態域名,有時會出現這樣的現象:如果ftp沒有開,有人以動態域名登陸時,動態域名的服務商會將你自動轉到它自己的提示性ftp,這時有可能出現密碼錯誤,也有可能登陸到它的伺服器。部分以iis為基礎建立的ftp有可能轉至微軟的伺服器,現象類同。

Thu Mar 07 11:51:25 2002 421 Too many users - please try again later.

這是因為ftp管理者設定了該帳號(或者該域名)的最大登陸人數,現在已經達到這一限制,因此你無法登陸。只有等待其他用戶退出或者使用其他賬號,你才可能進入ftp.

命令:> PASS *****
530 Not logged in, only one session from same IP allowed at a time.
錯誤:> 未登錄。
狀態:> 連接已關閉。
該帳號只允許單線程登陸,因此請注意你是否打開多個窗口或者已經有一個線程在下載

在登陸人數已滿,而你不斷嘗試登陸,有三種可能的情況:
1 你終於擠進去了
2 談出窗口提示錯誤,並在登陸錯誤指令見到這樣的字樣:
錯誤:> 控制連接已關閉。
表明ftp伺服器攔截你這樣頻繁的嘗試。你可以不管它,確定之後繼續嘗試;但是稍有道德的人都應該把ftp軟體的全局設置中關於連接重試嘗試的間隔時間修改到較大,一般提倡30秒到2分鍾。
3 你被ban了。serv-U所作的伺服器不能自動ban ip,但是管理者可以手工ban,部分伺服器端軟體可以自動封ip。被ban的提示為:
命令:> PASS *****
530 Not logged in, unauthorized IP address.

上面的提示
命令:> PASS *****
530 Not logged in, unauthorized IP address.
就是說你的ip是不合法的,不管是因為什麼原因,總之除非你與管理者聯系並解封,實在是沒有繼續嘗試的必要。當然,管理者可能只是ban你一段時間,你可以過後再重新嘗試。但是一定記得更改你的嘗試間隔時間。

有時候不是因為封了你,而是因為該帳號限制只有部分許可的ip可以登陸,同樣你必須與管理者聯系,請他手工添加你的ip

120 服務在nnn分鍾內贅好
125 數據連接已打開,贅傳送
150 文件狀態良好,打開數據連接
200 命令成功
202 命令未實現
211 系統狀態或系統幫助響應
212 目錄狀態
213 文件狀態
214 幫助信息,信息僅對人類用戶有用
215 名字系統類型
220 對新用戶服務贅好
221 服務關閉控制連接,可以退出登錄
225 數據連接打開,無傳輸正在進行
226 關閉數據連接,請求的文件*作成功
227 進入被動模式
230 用戶登錄
250 請求的文件*作完成
257 創建"PATHNAME"
331 用戶名正確,需要口令
332 登錄時需要帳戶信息
350 請求的文件*作需要進一步命令
421 連接用戶過多
425 不能打開數據連接
426 關閉連接,中止傳輸
450 請求的文件*作未執行
451 中止請求的*作:有本地錯誤
452 未執行請求的*作:系統存儲空間不足
500 格式錯誤,命令不可識別
501 參數語法錯誤
502 命令未實現
503 命令順序錯誤
504 此參數下的命令功能未實現
530 賬號或密碼錯誤
532 存儲文件需要帳戶信息
550 未執行請求的*作
551 請求*作中止:頁類型未知
552 請求的文件*作中止,存儲分配溢出
553 未執行請求的*作:文件名不合法

③ ftp上傳出現這個是為什麼.應該怎麼處理

150 opening ascii mode data connection for /bin/ls.
426 data connection closed, transfer aborted.

這種情況可能是你所在網路安裝了防火牆(或代理),該防火牆(或代理)禁止來自遠程的連接,426 data connection closed, transfer aborted表明了這一點。這時候你可以使用被動傳輸模式(pasv模式),來避免該限制,進行數據傳輸.
解決辦法是在該ftp標簽的站點設置中,設置為被動模式pasv模式.同樣,如果前面有網友出現200 port command successful.
連不上的情況,也用上面方法

1.
connected. waiting for response.
220 serv-u ftp server v4.0 for winsock ready...
user anonymous
530 sorry, no anonymous access allowed.
quit
不允許匿名登錄

2.

connected. waiting for response.
220 serv-u ftp server v4.0 for winsock ready...
user test
331 user name okay, need password.
pass xxxxxx
530 not logged in.
quit
一般是密碼輸入錯誤時出現的信息。密碼不對喲!

3.
connecting to xxx.xxx.xxx.xxx, port 21 (#1)
error: connection timed out

這個表明對方未開機,也可能是對方不在你能訪問的范圍內。可能小區的伺服器檢修中。

4.

connecting to xxx.xxx.xxx.xxx port 21 (#1)
error: connection refused
這個一般表明對方已開機,但未開啟ftp服務(沒有開serv-u)
也可能為對方不提供在這個埠上的服務

5.

connecting to xxx.xxx.xxx.xxx, port 21 (#1)
connected. waiting for response.
disconnected from server.
connection attempt failed. waiting for retry...
出現這個信息實在是很倒霉,你極有可能把重試時間定的太短伺服器封了你喲!

6.
connecting to xxx.xxx.xxx.xxx, port 21 (#1)
connected. waiting for response.
user xxx
331 user name okay, need password
pass xxxxxx
530 not logged in, unauthorized ip address.
quit
沒有登記ip!或者登記的ip和你現在下載的不一樣!趕快重新登記吧!

7.
227 entering passive mode (218,3,87,224,10,232)
retr hfdx-tsoaf.sub.rar
550 sorry, insufficient credit for download - upload first.
傳輸已失敗!
傳輸隊列已完成
你的流量不夠了,重新購買吧!

8.
connected. waiting for response.
220 serv-u ftp server v4.0 for winsock ready...
user user
421 too many users - please try again later.
說明當前你所屬的下載組的下載人數已到上限,請過些時候再嘗試,用Flashget等的下載工具不斷嘗試聯接的人請講嘗試時間調大一點,否則會被伺服器封閉一段時間的IP

9.
150 opening ascii mode data connection for /bin/ls.
426 data connection closed, transfer aborted.

這種情況可能是你所在網路安裝了防火牆(或代理),該防火牆(或代理)禁止來自遠程的連接,426 data connection closed, transfer aborted表明了這一點。這時候你可以使用被動傳輸模式(pasv模式),來避免該限制,進行數據傳輸.
解決辦法是在該ftp標簽的站點設置中,設置為被動模式pasv模式.同樣,如果前面有網友出現200 port command successful.
連不上的情況,也用上面方法

Connecting to xxx.xxx.xxx.xxx, Port 21 (#1)
ERROR: Connection timed out
這個表明對方未開機,也可能是對方不在你能訪問的范圍內
-----------------------------------
Connecting to xxx.xxx.xxx.xxx Port 21 (#1)
ERROR: Connection refused
這個一般表明對方已開機,但未開啟FTP服務(沒有開Serv-U)
也可能為對方不提供在這個埠上的服務
-----------------------------------
Connecting to xxx.xxx.xxx.xxx, Port 21 (#1)
Connected. Waiting for response.
Disconnected from server.
Connection attempt failed. Waiting for retry...
出現這個信息實在是很倒霉,你極有可能被對方Ban了。
如果只是Ban幾分鍾or幾小時or一天還好,不然只有和站長說說好話,讓他給你解封吧。

-----------------------------------
110 Restart marker reply. In this case, the text is exact and not left to
the particular implementation; it must read: MARK yyyy = mmmm where yyyy is
User-process data stream marker, and mmmm server s equivalent marker (note
the spaces between markers and "=").
重新啟動標志回應。這種情況下,信息是精確的並且不用特別的處理;可以這樣看:標記 yyyy = mmm 中 yyyy是 用戶進程數據流標記,mmmm是伺服器端相應的標記(注意在標記和等號間的空格)
-----------------------------------
120 Service ready in nnn minutes.
服務在NNN時間內可用
-----------------------------------
125 Data connection already open; transfer starting.
數據連接已經打開,開始傳送數據.
-----------------------------------
150 File status okay; about to open data connection.
文件狀態正確,正在打開數據連接.
-----------------------------------
200 Command okay.
命令執行正常結束.
-----------------------------------
202 Command not implemented, superfluous at this site.
命令未被執行,此站點不支持此命令.
-----------------------------------
211 System status, or system help reply.
系統狀態或系統幫助信息回應.
-----------------------------------
212 Directory status.
目錄狀態信息.
-----------------------------------
213 File status.
文件狀態信息.
-----------------------------------
214 Help message.On how to use the server or the meaning of a particular
non-standard command. This reply is useful only to the human user. 幫助信息。
關於如何使用本伺服器或特殊的非標准命令。此回復只對人有用。
-----------------------------------
215 NAME system type. Where NAME is an official system name from the list
in the Assigned Numbers document.
NAME系統類型。
-----------------------------------
220 Service ready for new user.
新連接的用戶的服務已就緒
-----------------------------------
221 Service closing control connection.
控制連接關閉
-----------------------------------
225 Data connection open; no transfer in progress.
數據連接已打開,沒有進行中的數據傳送
-----------------------------------
226 Closing data connection. Requested file action successful (for example,
file transfer or file abort).
正在關閉數據連接。請求文件動作成功結束(例如,文件傳送或終止)
-----------------------------------
227 Entering Passive Mode (h1,h2,h3,h4,p1,p2).
進入被動模式
-----------------------------------
230 User logged in, proceed. Logged out if appropriate.
用戶已登入。 如果不需要可以登出。
-----------------------------------
250 Requested file action okay, completed.
被請求文件操作成功完成
-----------------------------------
257 "PATHNAME" created.
路徑已建立
-----------------------------------
331 User name okay, need password.
用戶名存在,需要輸入密碼
-----------------------------------
332 Need account for login.
需要登陸的賬戶
-----------------------------------
350 Requested file action pending further information
對被請求文件的操作需要進一步更多的信息
-----------------------------------
421 Service not available, closing control connection.This may be a reply
to any command if the service knows it must shut down.
服務不可用,控制連接關閉。這可能是對任何命令的回應,如果服務認為它必須關閉
421 Too many users - please try again later.
太多用戶,那就過會再連
-----------------------------------
425 Can t open data connection.
打開數據連接失敗
-----------------------------------
426 Connection closed; transfer aborted.
連接關閉,傳送中止。
-----------------------------------
450 Requested file action not taken.
對被請求文件的操作未被執行
-----------------------------------
451 Requested action aborted. Local error in processing.
請求的操作中止。處理中發生本地錯誤。
-----------------------------------
452 Requested action not taken. Insufficient storage space in system.File
unavailable (e.g., file busy).
請求的操作沒有被執行。 系統存儲空間不足。 文件不可用
-----------------------------------
500 Syntax error, command unrecognized. This may include errors such as
command line too long.
語法錯誤,不可識別的命令。 這可能是命令行過長。
-----------------------------------
501 Syntax error in parameters or arguments.
參數錯誤導致的語法錯誤
-----------------------------------
502 Command not implemented.
命令未被執行
-----------------------------------
503 Bad sequence of commands.
命令的次序錯誤。
-----------------------------------
504 Command not implemented for that parameter.
由於參數錯誤,命令未被執行
-----------------------------------
530 Not logged in.
一般來說是密碼錯誤。
530 Sorry, no ANONYMOUS access allowed.
這個就是不許匿名登錄
530 Not logged in, unauthorized IP address
這個有點麻煩,你的IP不在站長允許訪問的IP范圍內,只有和站長聯系,讓他把你的IP網段加入Allow Access列表裡吧
530 Not logged in, only one(也有可能是two or three) session from same IP allowed at a time.
每個IP只能開一個(也有可能是two or three) 下載,就不要用多線程啦,小心Ban了你。
-----------------------------------
532 Need account for storing files.
存儲文件需要賬戶信息
-----------------------------------
550 Requested action not taken. File unavailable (e.g., file not found, no
access).
請求操作未被執行,文件不可用。
-----------------------------------
551 Requested action aborted. Page type unknown.
請求操作中止,頁面類型未知
-----------------------------------
552 Requested file action aborted. Exceeded storage allocation (for current
directory or dataset).
對請求文件的操作中止。 超出存儲分配
-----------------------------------
553 Requested action not taken. File name not allowed
請求操作未被執行。 文件名不允許
-----------------------------------
這種錯誤跟http協議類似,大致是:
2開頭--成功
3開頭--許可權問題
4開頭--文件問題
5開頭--伺服器問題

④ 關於如何實現FTP上傳或者下載帶進度和速率的實現方法

在這里需要說明的是,該方式是通過其他代碼進行改進的。 首先我們需要定義一個委託,用來實現傳輸過程中傳遞文件的總數,已完成的位元組數和速度,方便客戶端界面上調用。 public delegate void TransferProcess(long total,long finished,double speed); 調用代碼就不舉例了 接下來我們建立一個FTPClient類,該類基於socket和FTP協議實現了連接FTP服務,建立目錄,上傳文件,下載文件等主要方法。結構如下: 需要注意的是,我們需要定一個事件event TransferProcess OnTransferProcess;該事件在實例化FTPClient之後需要調用,這個事件對實現進度條和速率是非常重要的。為了實現速率我們還需要定義個公開的成員startTime(開始時間)。我們現在主要是看一下如何上傳的。 /// /// 上傳一個文件 /// /// 本地文件名 public void Put(string strFileName) { //連接伺服器 if (!bConnected) { Connect(); } UpdateStatus = true; //建立socket連接 Socket socketData = CreateDataSocket(); //向FTP伺服器發生存儲命令 SendCommand("STOR " + Path.GetFileName(strFileName)); //如何伺服器返回的信息不是我們所需要的,就拋出異常 if (!(iReplyCode == 125 || iReplyCode == 150)) { throw new IOException(strReply.Substring(4)); } //建立本地文件的數據流 FileStream input = new FileStream(strFileName, FileMode.Open); int iBytes = 0; long total = input.Length;//該成員主要記錄文件的總位元組數,注意這里使用長整型,是為了突破只能傳輸2G左右的文件的限制 long finished = 0;//該成員主要記錄已經傳輸完成的位元組數,注意這里使用長整型,是為了突破只能傳輸2G左右的文件的限制 double speed = 0;//記錄傳輸的速率 while ((iBytes = input.Read(buffer, 0, buffer.Length)) > 0)//循環從本地數據流中讀取數據到緩沖區 { //Console.WriteLine(startTime.ToString()); socketData.Send(buffer, iBytes, 0);//將緩沖區的數據發送到FTP伺服器 DateTime endTime = DateTime.Now;//每次發送數據的結束時間 TimeSpan ts = endTime - startTime;//計算每次發送數據的時間間隔 finished += iBytes;//計算完成的位元組數. Console.WriteLine(ts.Milliseconds); //計算速率,注意finished是位元組,所以需要換算沖K位元組 if (ts.Milliseconds > 0) { speed = (double)(finished / ts.TotalMilliseconds); speed = Math.Round(speed * 1000 / 1024, 2); } //這里是必不可少的,否則你無法實現進度條 //如果傳輸進度事件被實例化,而且從本地數據流中讀取數據不是空的並完成的位元組數也不為空的話,則實現委託. if (OnTransferProcess != null&&iBytes>0&&finished>0) { OnTransferProcess(total, finished,speed); } } UpdateStatus = false; finished = 0; input.Close();//當傳輸完成之後需要關閉數據流,以便下次訪問. if (socketData.Connected) { socketData.Close();//關閉當前的socket } if (!(iReplyCode == 226 || iReplyCode == 250)) { ReadReply(); if (!(iReplyCode == 226 || iReplyCode == 250)) { UpdateStatus = false; throw new IOException(strReply.Substring(4)); } } } 上面代碼中注釋寫得比較詳細,這里就不再一一講解了,關於下載中實現進度條和速率的問題可以參考以上代碼進行修改. 完整的代碼如下: using System; using System.net; using System.IO; using System.Text; using System.net.Sockets; namespace MMSEncoder { public delegate void TransferProcess(long total,long finished,double speed); /// /// FTP Client /// public class FTPClient { public event TransferProcess OnTransferProcess; public bool UpdateStatus = true; public DateTime startTime; private bool IsAbortConnect = false; #region 構造函數 /// /// 預設構造函數 /// public FTPClient() { strRemoteHost = ""; strRemotePath = ""; strRemoteUser = ""; strRemotePass = ""; strRemotePort = 21; bConnected = false; } /// /// 構造函數 /// /// FTP伺服器IP地址 /// 當前伺服器目錄 /// 登錄用戶賬號 /// 登錄用戶密碼 /// FTP伺服器埠 public FTPClient(string remoteHost, string remotePath, string remoteUser, string remotePass, int remotePort) { strRemoteHost = remoteHost; strRemotePath = remotePath; strRemoteUser = remoteUser; strRemotePass = remotePass; strRemotePort = remotePort; Connect(); } #endregion #region 登陸欄位、屬性 /// /// FTP伺服器IP地址 /// private string strRemoteHost; public string RemoteHost { get { return strRemoteHost; } set { strRemoteHost = value; } } /// /// FTP伺服器埠 /// private int strRemotePort; public int RemotePort { get { return strRemotePort; } set { strRemotePort = value; } } /// /// 當前伺服器目錄 /// private string strRemotePath; public string RemotePath { get { return strRemotePath; } set { strRemotePath = value; } } /// /// 登錄用戶賬號 /// private string strRemoteUser; public string RemoteUser { set { strRemoteUser = value; } } /// /// 用戶登錄密碼 /// private string strRemotePass; public string RemotePass { set { strRemotePass = value; } } /// /// 是否登錄 /// private Boolean bConnected; public bool Connected { get { return bConnected; } } #endregion #region 鏈接 /// /// 建立連接 /// public void Connect() { //if (IsAbortConnect) throw new IOException("用戶強制終止了FTP"); socketControl = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPEndPoint ep = new IPEndPoint(IPAddress.Parse(RemoteHost), strRemotePort); // 鏈接 try { socketControl.Connect(ep); } catch (Exception) { throw new IOException("無法連接到遠程伺服器!"); } // 獲取應答碼 ReadReply(); if (iReplyCode != 220) { DisConnect(); throw new IOException(strReply.Substring(4)); } // 登陸 SendCommand("USER " + strRemoteUser); if (!(iReplyCode == 331 || iReplyCode == 230)) { CloseSocketConnect();//關閉連接 throw new IOException(strReply.Substring(4)); } if (iReplyCode != 230) { SendCommand("PASS " + strRemotePass); if (!(iReplyCode == 230 || iReplyCode == 202)) { CloseSocketConnect();//關閉連接 throw new IOException(strReply.Substring(4)); } } bConnected = true; // 切換到初始目錄 if (!string.IsNullOrEmpty(strRemotePath)) { ChDir(strRemotePath); } } /// /// 關閉連接 /// public void DisConnect() { if (socketControl != null) { SendCommand("QUIT"); } CloseSocketConnect(); } public void AbortConnect() { if (socketControl != null) { SendCommand("ABOR"); } IsAbortConnect = true; //CloseSocketConnect(); } #endregion #region 傳輸模式 /// /// 傳輸模式:二進制類型、ASCII類型 /// public enum TransferType { Binary, ASCII }; /// /// 設置傳輸模式 /// /// 傳輸模式 public void SetTransferType(TransferType ttType) { if (ttType == TransferType.Binary) { SendCommand("TYPE I");//binary類型傳輸 } else { SendCommand("TYPE A");//ASCII類型傳輸 } if (iReplyCode != 200) { throw new IOException(strReply.Substring(4)); } else { trType = ttType; } } /// /// 獲得傳輸模式 /// /// 傳輸模式 public TransferType GetTransferType() { return trType; } #endregion #region 文件操作 /// /// 獲得文件列表 /// /// 文件名的匹配字元串 /// public string[] Dir(string strMask) { // 建立鏈接 if (!bConnected) { Connect(); } //建立進行數據連接的socket Socket socketData = CreateDataSocket(); //傳送命令 SendCommand("NLST " + strMask); //分析應答代碼 if (!(iReplyCode == 150 || iReplyCode == 125 || iReplyCode == 226)) { throw new IOException(strReply.Substring(4)); } //獲得結果 strMsg = ""; while (true) { int iBytes = socketData.Receive(buffer, buffer.Length, 0); strMsg += GB2312.GetString(buffer, 0, iBytes); if (iBytes < buffer.Length) { break; } } char[] seperator = { '
' }; string[] strsFileList = strMsg.Split(seperator); socketData.Close();//數據socket關閉時也會有返回碼 if (iReplyCode != 226) { ReadReply(); if (iReplyCode != 226) { throw new IOException(strReply.Substring(4)); } } return strsFileList; } /// /// 獲取文件大小 /// /// 文件名 /// 文件大小 public long GetFileSize(string strFileName) { if (!bConnected) { Connect(); } SendCommand("SIZE " + Path.GetFileName(strFileName)); long lSize = 0; if (iReplyCode == 213) { lSize = Int64.Parse(strReply.Substring(4)); } else { throw new IOException(strReply.Substring(4)); } return lSize; } /// /// 刪除 /// /// 待刪除文件名 public void Delete(string strFileName) { if (!bConnected) { Connect(); } SendCommand("DELE " + strFileName); if (iReplyCode != 250) { throw new IOException(strReply.Substring(4)); } } /// /// 重命名(如果新文件名與已有文件重名,將覆蓋已有文件) /// /// 舊文件名 /// 新文件名 public void Rename(string strOldFileName, string strNewFileName) { if (!bConnected) { Connect(); } SendCommand("RNFR " + strOldFileName); if (iReplyCode != 350) { throw new IOException(strReply.Substring(4)); } // 如果新文件名與原有文件重名,將覆蓋原有文件 SendCommand("RNTO " + strNewFileName); if (iReplyCode != 250) { throw new IOException(strReply.Substring(4)); } } #endregion #region 上傳和下載 /// /// 下載一批文件 /// /// 文件名的匹配字元串 /// 本地目錄(不得以\結束) public void Get(string strFileNameMask, string strFolder) { if (!bConnected) { Connect(); } string[] strFiles = Dir(strFileNameMask); foreach (string strFile in strFiles) { if (!strFile.Equals(""))//一般來說strFiles的最後一個元素可能是空字元串 { if (strFile.LastIndexOf(".") > -1) { Get(strFile.Replace("\r", ""), strFolder, strFile.Replace("\r", "")); } } } } /// /// 下載一個文件 /// /// 要下載的文件名 /// 本地目錄(不得以\結束) /// 保存在本地時的文件名 public void Get(string strRemoteFileName, string strFolder, string strLocalFileName) { if (!bConnected) { Connect(); } SetTransferType(TransferType.Binary); if (strLocalFileName.Equals("")) { strLocalFileName = strRemoteFileName; } if (!File.Exists(strLocalFileName)) { Stream st = File.Create(strLocalFileName); st.Close(); } FileStream output = new FileStream(strFolder + "\\" + strLocalFileName, FileMode.Create); Socket socketData = CreateDataSocket(); SendCommand("RETR " + strRemoteFileName); if (!(iReplyCode == 150 || iReplyCode == 125 || iReplyCode == 226 || iReplyCode == 250)) { throw new IOException(strReply.Substring(4)); } while (true) { int iBytes = socketData.Receive(buffer, buffer.Length, 0); output.Write(buffer, 0, iBytes); if (iBytes <= 0) { break; } } output.Close(); if (socketData.Connected) { socketData.Close(); } if (!(iReplyCode == 226 || iReplyCode == 250)) { ReadReply(); if (!(iReplyCode == 226 || iReplyCode == 250)) { throw new IOException(strReply.Substring(4)); } } } /// /// 上傳一批文件 /// /// 本地目錄(不得以\結束) /// 文件名匹配字元(可以包含*和?) public void Put(string strFolder, string strFileNameMask) { string[] strFiles = Directory.GetFiles(strFolder, strFileNameMask); foreach (string strFile in strFiles) { //strFile是完整的文件名(包含路徑) Put(strFile); } } /// /// 上傳一個文件 /// /// 本地文件名 public void Put(string strFileName) { if (!bConnected) { Connect(); } UpdateStatus = true; Socket socketData = CreateDataSocket(); SendCommand("STOR " + Path.GetFileName(strFileName)); if (!(iReplyCode == 125 || iReplyCode == 150)) { throw new IOException(strReply.Substring(4)); } FileStream input = new FileStream(strFileName, FileMode.Open); int iBytes = 0; long total = input.Length; long finished = 0; //DateTime startTime = DateTime.Now; double speed = 0; while ((iBytes = input.Read(buffer, 0, buffer.Length)) > 0) { Console.WriteLine(startTime.ToString()); socketData.Send(buffer, iBytes, 0); DateTime endTime = DateTime.Now; TimeSpan ts = endTime - startTime; finished += iBytes; Console.WriteLine(ts.Milliseconds); if (ts.Milliseconds > 0) { speed = (double)(finished / ts.TotalMilliseconds); speed = Math.Round(speed * 1000 / 1024, 2); } if (OnTransferProcess != null&&iBytes>0&&finished>0) { OnTransferProcess(total, finished,speed); } } UpdateStatus = false; finished = 0; input.Close(); if (socketData.Connected) { socketData.Close(); } if (!(iReplyCode == 226 || iReplyCode == 250)) { ReadReply(); if (!(iReplyCode == 226 || iReplyCode == 250)) { UpdateStatus = false; throw new IOException(strReply.Substring(4)); } } } #endregion #region 目錄操作 /// /// 創建目錄 /// /// 目錄名 public void MkDir(string strDirName) { if (!bConnected) { Connect(); } SendCommand("MKD " + strDirName); if (iReplyCode != 257) { throw new IOException(strReply.Substring(4)); } } /// /// 刪除目錄 /// /// 目錄名 public void RmDir(string strDirName) { if (!bConnected) { Connect(); } SendCommand("RMD " + strDirName); if (iReplyCode != 250) { throw new IOException(strReply.Substring(4)); } } /// /// 改變目錄 /// /// 新的工作目錄名 public void ChDir(string strDirName) { if (strDirName.Equals(".") || strDirName.Equals("")) { return; } if (!bConnected) { Connect(); } SendCommand("CWD " + strDirName); if (iReplyCode != 250) { throw new IOException(strReply.Substring(4)); } this.strRemotePath = strDirName; } #endregion #region 內部變數 /// /// 伺服器返回的應答信息(包含應答碼) /// private string strMsg; /// /// 伺服器返回的應答信息(包含應答碼) /// private string strReply; /// /// 伺服器返回的應答碼 /// private int iReplyCode; /// /// 進行控制連接的socket /// private Socket socketControl; /// /// 傳輸模式 /// private TransferType trType; /// /// 接收和發送數據的緩沖區 /// private static int BLOCK_SIZE = Int16.MaxValue; Byte[] buffer = new Byte[BLOCK_SIZE]; /// /// 編碼方式(為防止出現中文亂碼採用 GB2312編碼方式) /// Encoding GB2312 = Encoding.Default ;//Encoding.GetEncoding("gb2312"); #endregion #region 內部函數 /// /// 將一行應答字元串記錄在strReply和strMsg /// 應答碼記錄在iReplyCode /// private void ReadReply() { strMsg = ""; strReply = ReadLine(); iReplyCode = Int32.Parse(strReply.Substring(0, 3)); } /// /// 建立進行數據連接的socket /// /// 數據連接socket private Socket CreateDataSocket() { SendCommand("PASV"); if (iReplyCode != 227) { throw new IOException(strReply.Substring(4)); } int index1 = strReply.IndexOf('('); int index2 = strReply.IndexOf(')'); string ipData = strReply.Substring(index1 + 1, index2 - index1 - 1); int[] parts = new int[6]; int len = ipData.Length; int partCount = 0; string buf = ""; for (int i = 0; i < len && partCount <= 6; i++) { char ch = Char.Parse(ipData.Substring(i, 1)); if (Char.IsDigit(ch)) buf += ch; else if (ch != ',') { throw new IOException("Malformed PASV strReply: " + strReply); } if (ch == ',' || i + 1 == len) { try { parts[partCount++] = Int32.Parse(buf); buf = ""; } catch (Exception) { throw new IOException("Malformed PASV strReply: " + strReply); } } } string ipAddress = parts[0] + "." + parts[1] + "." + parts[2] + "." + parts[3]; int port = (parts[4] << 8) + parts[5]; Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPEndPoint ep = new IPEndPoint(IPAddress.Parse(ipAddress), port); try { s.Connect(ep); } catch (Exception) { throw new IOException("無法連接伺服器"); } return s; } /// /// 關閉socket連接(用於登錄以前) /// private void CloseSocketConnect() { if (socketControl != null) { socketControl.Close(); socketControl = null; } bConnected = false; } /// /// 讀取Socket返回的所有字元串 /// /// 包含應答碼的字元串列 private string ReadLine() { while (true) { int iBytes = socketControl.Receive(buffer, buffer.Length, 0); strMsg += GB2312.GetString(buffer, 0, iBytes); if (iBytes < buffer.Length) { break; } } char[] seperator = { '
' }; string[] mess = strMsg.Split(seperator); if (strMsg.Length > 2) { strMsg = mess[mess.Length - 2]; //seperator[0]是10,換行符是由13和0組成的,分隔後10後面雖沒有字元串, //但也會分配為空字元串給後面(也是最後一個)字元串數組, //所以最後一個mess是沒用的空字元串 //但為什麼不直接取mess[0],因為只有最後一行字元串應答碼與信息之間有空格 } else { strMsg = mess[0]; } if (!strMsg.Substring(3, 1).Equals(" "))//返回字元串正確的是以應答碼(如220開頭,後面接一空格,再接問候字元串) { return ReadLine(); } return strMsg; } /// /// 發送命令並獲取應答碼和最後一行應答字元串 /// /// 命令 private void SendCommand(String strCommand) { Byte[] cmdBytes = GB2312.GetBytes((strCommand + "\r
").ToCharArray()); socketControl.Send(cmdBytes, cmdBytes.Length, 0); ReadReply(); } #endregion } }

⑤ ftp 250 和 226的區別

FTP連接過程中,提示530 Login authentication failed錯誤是因為填寫錯了ftp密碼。
解決方法:
登陸客戶中心,客戶中心 > 會員中心 > 產品與服務(不同的主機提供商可能不同僅供參考)進入購買的那個套餐,下面有個登陸詳情然後輸入新密碼就行了,這樣ftp就可以用了。

FTP登錄常見提示錯誤:
1.connected. waiting for response. 220 serv-u ftp server v4.0 for winsock ready...
user anonymous 530 sorry, no anonymous access allowed. quit
不允許匿名登錄
2.connected. waiting for response. 220 serv-u ftp server v4.0 for winsock ready...
user test 331 user name okay, need password. pass xxxxxx 530 not logged in. quit 一般是密碼輸入錯誤時出現的信息。
3.connecting to xxx.xxx.xxx.xxx, port 21 error: connection timed out
這個表明對方未開機,也可能是對方不在能訪問的范圍內。可能小區的伺服器檢修中。
4.connecting to xxx.xxx.xxx.xxx port 21 error: connection refused
這個一般表明對方已開機,但未開啟ftp服務(沒有開serv-u),也可能為對方不提供在這個埠上的服務
5.connecting to xxx.xxx.xxx.xxx, port 21 connected. waiting for response. disconnected from server. connection attempt failed. waiting for retry...
出現極有可能是重試時間定的太短被伺服器封了。
6.connecting to xxx.xxx.xxx.xxx, port 21 connected. waiting for response. user xxx
331 user name okay, need password pass xxxxxx 530 not logged in, unauthorized ip address. quit
沒有登記ip,或者登記的ip和現在的不一樣,重新登記即可。
7.227 entering passive mode (218,3,87,224,10,232) retr hfdx-tsoaf.sub.rar 550 sorry, insufficient credit for download - upload first.
傳輸已失敗.傳輸隊列已完成但流量不夠了,重新購買。

⑥ FTP連接失敗的原因

考慮以下原因:

1、防火牆擋住了

2、沒有查看內容的許可權

3、網管屏蔽了FTP埠

默認是pasv模式,因為服務端防火牆的設置,客戶端不能用pasv模式,將設置中的pasv模式置為空,就正常了

FTP連接伺服器失敗的原因一般有以下幾種:

1、網路不通導致FTP連接伺服器失敗

有時可能是由伺服器或者電腦本地網路有問題,導致FTP連接伺服器失敗。可以通過瀏覽器查看網頁測試是否是網路問題。

2、伺服器出現宕機、死機、重啟等情況

我們在租用伺服器時,都會對伺服器的訪問速度及穩定性進行考察。伺服器出現右機、死機、重啟等情況不僅會導致FIP連接伺服器失敗,也直接導致網站無法正常運營,從而影響網站優化排名及用戶體驗。如果出現此情況,盡快聯系伺服器提供商進行解決。

3、防火牆設置出現問題導致伺服器連接失敗查看我們的防火牆設置是否勾選了「PASV模式」,如果勾選,那麼將取消,然後嘗試重新連接。

4、FTP軟體出現問題導致連接伺服器失敗有時我們會忘記對軟體的及時更新,所以導致使用的FTP軟體版本過低或者被停用,再或者該軟體出現了問題。此時我們可以先刪除現有軟體,然後重新安裝。

5、短時間內連接伺服器次數過多

可能由於FTP連接伺服器的速度稍微有些慢,我們等待的比較著急,就不停地點擊連接按鈕,導致短時間內容連接次數過於頻繁而連接失敗。

6、伺服器被ISP屏蔽導致FTP連接伺服器失敗判斷伺服器是否被ISP屏蔽,可以通過使用代理伺服器進行連接測試。

7、租用的伺服器後台被關閉

如果以上幾種情況都被排除,那麼很有可能是我們所租用的伺服器後台被關閉了,此時需要連接伺服器提供商進行核查與修改。

FTP連接伺服器失敗的原因有很多,基本比較常見的情況就是以上幾種。為保障網站的正常運營,當出現FTP伺服器失敗的情況,應及時檢查其原因並解決。

拓展資料:

FTP是File Transfer Protocol(文件傳輸協議)的縮寫,用來在兩台計算機之間互相傳送文件。相比於HTTP,FTP協議要復雜得多。復雜的原因,是因為FTP協議要用到兩個TCP連接,一個是命令鏈路,用來在FTP客戶端與伺服器之間傳遞命令;另一個是數據鏈路,用來上傳或下載數據。

⑦ 請解釋一下FTP連接的命令及響應

FTP命令
命令 描述
ABOR 中斷數據連接程序
ACCT <account> 系統特權帳號
ALLO <bytes> 為伺服器上的文件存儲器分配位元組
APPE <filename> 添加文件到伺服器同名文件
CDUP <dir path> 改變伺服器上的父目錄
CWD <dir path> 改變伺服器上的工作目錄
DELE <filename> 刪除伺服器上的指定文件
HELP <command> 返回指定命令信息
LIST <name> 如果是文件名列出文件信息,如果是目錄則列出文件列表
MODE <mode> 傳輸模式(S=流模式,B=塊模式,C=壓縮模式)
MKD <directory> 在伺服器上建立指定目錄
NLST <directory> 列出指定目錄內容
NOOP 無動作,除了來自伺服器上的承認
PASS <password> 系統登錄密碼
PASV 請求伺服器等待數據連接
PORT <address> IP 地址和兩位元組的埠 ID
PWD 顯示當前工作目錄
QUIT 從 FTP 伺服器上退出登錄
REIN 重新初始化登錄狀態連接
REST <offset> 由特定偏移量重啟文件傳遞
RETR <filename> 從伺服器上找回(復制)文件
RMD <directory> 在伺服器上刪除指定目錄
RNFR <old path> 對舊路徑重命名
RNTO <new path> 對新路徑重命名
SITE <params> 由伺服器提供的站點特殊參數
SMNT <pathname> 掛載指定文件結構
STAT <directory> 在當前程序或目錄上返回信息
STOR <filename> 儲存(復制)文件到伺服器上
STOU <filename> 儲存文件到伺服器名稱上
STRU <type> 數據結構(F=文件,R=記錄,P=頁面)
SYST 返回伺服器使用的操作系統
TYPE <data type> 數據類型(A=ASCII,E=EBCDIC,I=binary)
USER <username>> 系統登錄的用戶名

FTP響應碼

響應代碼 解釋說明
110 新文件指示器上的重啟標記
120 伺服器准備就緒的時間(分鍾數)
125 打開數據連接,開始傳輸
150 打開連接
200 成功
202 命令沒有執行
211 系統狀態回復
212 目錄狀態回復
213 文件狀態回復
214 幫助信息回復
215 系統類型回復
220 服務就緒
221 退出網路
225 打開數據連接
226 結束數據連接
227 進入被動模式(IP 地址、ID 埠)
230 登錄網際網路
250 文件行為完成
257 路徑名建立
331 要求密碼
332 要求帳號
350 文件行為暫停
421 服務關閉
425 無法打開數據連接
426 結束連接
450 文件不可用
451 遇到本地錯誤
452 磁碟空間不足
500 無效命令
501 錯誤參數
502 命令沒有執行
503 錯誤指令序列
504 無效命令參數
530 未登錄網路
532 存儲文件需要帳號
550 文件不可用
551 不知道的頁類型
552 超過存儲分配
553 文件名不允許

⑧ 連接FTP時報錯,救,該怎麼解決

一:要用比較新的版本的FTP.

二:不僅要把自己裝的防火牆調低或關掉還要尤其是XP系統帶的防火牆關掉。

三:FTP設置時,請勿選擇在PASV模式下上傳,否則將出現登錄FTP後,無法列表等異常情況。相同的軟體,版本不同,設置方法也略有不同,因此需要根據實際情況進行設置。

四:檢查埠以及賬號密碼。

五:聯系空間提供商。

參考資料:http://www.yaya.cn

⑨ ftp信息是什麼呀

FTP信息代碼全解
110 Restart marker reply. In this case, the text is exact and not left to the particular implementation; it must read: MARK yyyy = mmmm where yyyy is User-process data stream marker, and mmmm server's equivalent marker (note the spaces between markers and "=").
重新啟動標志回應。這種情況下,信息是精確的並且不用特別的處理;可以這樣看:標記 yyyy = mmm 中 yyyy是 用戶進程數據流標記,mmmm是伺服器端相應的標記(注意在標記和等號間的空格)
-----------------------------------
120 Service ready in nnn minutes.
服務在NNN時間內可用
-----------------------------------
125 Data connection already open; transfer starting.
數據連接已經打開,開始傳送數據.
-----------------------------------
150 File status okay; about to open data connection.
文件狀態正確,正在打開數據連接.
-----------------------------------
200 Command okay.
命令執行正常結束.
-----------------------------------
202 Command not implemented, superfluous at this site.
命令未被執行,此站點不支持此命令.
-----------------------------------
211 System status, or system help reply.
系統狀態或系統幫助信息回應.
-----------------------------------
212 Directory status.
目錄狀態信息.
-----------------------------------
213 File status.
文件狀態信息.
-----------------------------------
214 Help message.On how to use the server or the meaning of a particular non-standard command. This reply is useful only to the human user. 幫助信息。關於如何使用本伺服器或特殊的非標准命令。此回復只對人有用。
-----------------------------------
215 NAME system type. Where NAME is an official system name from the list in the Assigned Numbers document.
NAME系統類型。
-----------------------------------
220 Service ready for new user.
新連接的用戶的服務已就緒
-----------------------------------
221 Service closing control connection.
控制連接關閉
-----------------------------------
225 Data connection open; no transfer in progress.
數據連接已打開,沒有進行中的數據傳送
-----------------------------------
226 Closing data connection. Requested file action successful (for example, file transfer or file abort).
正在關閉數據連接。請求文件動作成功結束(例如,文件傳送或終止)
-----------------------------------
227 Entering Passive Mode (h1,h2,h3,h4,p1,p2).
進入被動模式
-----------------------------------
230 User logged in, proceed. Logged out if appropriate.
用戶已登入。 如果不需要可以登出。
-----------------------------------
250 Requested file action okay, completed.
被請求文件操作成功完成
-----------------------------------
257 "PATHNAME" created.
路徑已建立
-----------------------------------
331 User name okay, need password.
用戶名存在,需要輸入密碼
-----------------------------------
332 Need account for login.
需要登陸的賬戶
-----------------------------------
350 Requested file action pending further information
對被請求文件的操作需要進一步更多的信息
-----------------------------------
421 Service not available, closing control connection.This may be a reply to any command if the service knows it must shut down.
服務不可用,控制連接關閉。這可能是對任何命令的回應,如果服務認為它必須關閉
-----------------------------------
425 Can't open data connection.
打開數據連接失敗
-----------------------------------
426 Connection closed; transfer aborted.
連接關閉,傳送中止。
-----------------------------------
450 Requested file action not taken.
對被請求文件的操作未被執行
-----------------------------------
451 Requested action aborted. Local error in processing.
請求的操作中止。處理中發生本地錯誤。
-----------------------------------
452 Requested action not taken. Insufficient storage space in system.File unavailable (e.g., file busy).
請求的操作沒有被執行。 系統存儲空間不足。 文件不可用
-----------------------------------
500 Syntax error, command unrecognized. This may include errors such as command line too long.
語法錯誤,不可識別的命令。 這可能是命令行過長。
-----------------------------------
501 Syntax error in parameters or arguments.
參數錯誤導致的語法錯誤
-----------------------------------
502 Command not implemented.
命令未被執行
-----------------------------------
503 Bad sequence of commands.
命令的次序錯誤。
-----------------------------------
504 Command not implemented for that parameter.
由於參數錯誤,命令未被執行
-----------------------------------
530 Not logged in.
沒有登錄
-----------------------------------
532 Need account for storing files.
存儲文件需要賬戶信息
-----------------------------------
550 Requested action not taken. File unavailable (e.g., file not found, no access).
請求操作未被執行,文件不可用。
-----------------------------------
551 Requested action aborted. Page type unknown.
請求操作中止,頁面類型未知
-----------------------------------
552 Requested file action aborted. Exceeded storage allocation (for current directory or dataset).
對請求文件的操作中止。 超出存儲分配
-----------------------------------
553 Requested action not taken. File name not allowed
請求操作未被執行。 文件名不允許
-----------------------------------
-----------------------------------
這種錯誤跟http協議類似,大致是:
2開頭--成功
3開頭--許可權問題
4開頭--文件問題
5開頭--伺服器問題