解決了一個 java7 發送 ftp 檔案失敗的問題

來源:互聯網
上載者:User

近日寫程式,使用 apache common net 裡的 FTPClient,往 FTP 伺服器上,上傳檔案,以至失敗。糾結了兩三天,不能解決。

 

後上網 google 搜尋,發現以下網址提到著這件事情:

 

Java 7 prevents FTP transfers on Windows Vista and 7 if firewall is on. Any ideas?

http://stackoverflow.com/questions/6990663/java-7-prevents-ftp-transfers-on-windows-vista-and-7-if-firewall-is-on-any-idea

 

裡面提到,這是 java 的一個 bug(Submit Date,  11-AUG-2011 ):

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7077696

但是 Sun 公司標註這是一個低層級的 bug。

具體原因是:在安裝有 IPv6 和 IPv4 的電腦上,會使用一種 IPv6 類比的 IPv4(The only difference between JDK7 and older releases is that the JDK is using IPv6 sockets when IPv6 is enabled and so IPv4-mapped IPv6 addresses are used),而 windows 防火牆會把這種類比的 IPv4 資料擋住。

 

我很奇怪,它只擋住了 FTP 命令 PASV, 對於FTP 登入操作什麼的,沒有擋住。

最後,Sun 公司給出解決方案:加一個 JVM 啟動參數:

run with -Djava.net.preferIPv4Stack=true (which disables IPv6 and uses AF_INET sockets exclusively)

 

經測試,確實有效。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.