Looking for help diagnosing server socket problem

2019-05-30 19:55发布

I have developed a web based application which allows a client/user to upload a file to JVM memory. The server side code then FTP's the file to another server. This all works fine and dandy on my local machine, but I'm now running into problems getting this to work on our test environment servers.

On the test environment server, the code successfully connects and logs in to the remote Windows server, but hangs during file transfer. An empty file is created on the destination server but no bytes are transferred. Stack trace from JVM which eventually killed the thread:

[10/08/11 14:45:24:234 BST] 00000003 ThreadMonitor W   WSVR0605W: Thread "WebContainer : 2" (00000033) has been active for 666083 milliseconds and may be hung.  There is/are 1 thread(s) in total in the server that may be hung.
at java.net.PlainSocketImpl.socketAccept(Native Method)
at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:431)
at java.net.ServerSocket.implAccept(ServerSocket.java:464)
at java.net.ServerSocket.accept(ServerSocket.java:432)
at org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:693)
at org.apache.commons.net.ftp.FTPClient.__storeFile(FTPClient.java:551)
at org.apache.commons.net.ftp.FTPClient.storeFile(FTPClient.java:1704)
... (my own app code stack trace from here on down)

Looks like a socket issue, but can anyone help me figure out on which machine the issue is on? Is it the test environment JVM or is it the destination Windows server? I'm guessing its the test environment server, otherwise I would have seen this issue on my local machine? If it is on the test environment server, is it a matter of opening up ports (and if so what do I ask for)? Any help most appreciated.

1条回答
Fickle 薄情
2楼-- · 2019-05-30 20:26

It sounds like a firewall problem to me, which may be solved by using passive mode for the FTP client. When in active mode, the FTP server tries to initiate a connection to the FTP client when transferring a file and the firewall/WAS may not like that.

According to the docs for commons ftpclient, the default mode is ACTIVE, so in your code, try calling

ftpclient.enterLocalPassiveMode();

after the connect, but before the file transfer.

查看更多
登录 后发表回答