FTPClient中使用completePendingCommand方法注意事項

方法介紹:

* There are a few FTPClient methods that do not complete the * entire sequence of FTP commands to complete a transaction. These * commands require some action by the programmer after the reception * of a positive intermediate command. After the programmer's code * completes its actions, it must call this method to receive * the completion reply from the server and verify the success of the * entire transaction. public boolean completePendingCommad() throws IOException; { return FTPReply.isPositiveCompletion(getReply()); } 

方法介紹中未說明,在何種狀況下應該使用該方法。可是跟蹤代碼能夠發現
這是一個同步阻塞方法,若是調用錯誤,會致使程序卡住假死在這裏。javascript

卡住代碼
 String line = _controlInput_.readLine(); 

什麼時候調用?

其實ftp功能,總結來講,只有上傳和下載。只有在獲取返回流時,才須要調用completePendingCommad方法,由於返回流不是馬上處理的。因此需用手動調用結束方法。html

public boolean storeFile(String remote, InputStream local) public OutputStream storeFileStream(String remote) public boolean retrieveFile(String remote, OutputStream local) public InputStream retrieveFileStream(String remote) 

咱們看到上面4我的方法,其中兩個有流返回,另外兩個無返回。當調用有返回流方法時,須要手動調用completePendingCommad方法,即第二個和第四個是須要調用completePendingCommad方法,其餘兩個方法若是調用了,則會產生卡死超時現象。java

注意事項

不可多加或者漏加,不然會致使程序卡死ui

參考連接

commons-net FTPClient API存取設計this

Commons-net FTPClient completePendingCommand()常常使程序死掉的緣由分析以及解決方式spa

做者:北海北_6dc3 連接:https://www.jianshu.com/p/a90cc2aeefca 來源:簡書 簡書著做權歸做者全部,任何形式的轉載都請聯繫做者得到受權並註明出處。
相關文章
相關標籤/搜索