使用 enterprisedt 的 ftp java 框架调用disconnect()时连接重置
我在使用 enterpriset java ftp 框架从 ftp 服务器断开连接时遇到问题。< /a>
我无法在 FileTransferClient 对象上调用 disconnect() 而不出现错误。
除了连接到服务器,然后断开连接之外,我没有做任何事情:
// create client
log.info("Creating FTP client");
ftp = new FileTransferClient();
// set remote host
log.info("Setting remote host");
ftp.setRemoteHost(host);
ftp.setUserName(username);
ftp.setPassword(password);
// connect to the server
log.info("Connecting to server " + host);
ftp.connect();
log.info("Connected and logged in to server " + host);
// Shut down client
log.info("Quitting client");
ftp.disconnect();
log.info("Example complete");
运行此程序时,日志显示:
INFO [test] 28 maj 2010 16:57:20.216 : Creating FTP client
INFO [test] 28 maj 2010 16:57:20.263 : Setting remote host
INFO [test] 28 maj 2010 16:57:20.263 : Connecting to server x
INFO [test] 28 maj 2010 16:57:20.979 : Connected and logged in to server x
INFO [test] 28 maj 2010 16:57:20.979 : Quitting client
ERROR [FTPControlSocket] 28 maj 2010 16:57:21.026 : Read failed ('' read so far)
并且堆栈跟踪:
com.enterprisedt.net.ftp.ControlChannelIOException: Connection reset
at com.enterprisedt.net.ftp.FTPControlSocket.readLine(FTPControlSocket.java:1029)
at com.enterprisedt.net.ftp.FTPControlSocket.readReply(FTPControlSocket.java:1089)
at com.enterprisedt.net.ftp.FTPControlSocket.sendCommand(FTPControlSocket.java:988)
at com.enterprisedt.net.ftp.FTPClient.quit(FTPClient.java:4044)
at com.enterprisedt.net.ftp.FileTransferClient.disconnect(FileTransferClient.java:1034)
at test.main(test.java:46)
应该注意的是,我可以毫无问题地连接并与服务器一起执行操作,例如获取当前工作目录中的文件列表。但由于某种原因我无法断开连接!我尝试过使用主动模式和被动模式。
上面的例子是从他们自己的例子中复制/粘贴的。我无法通过谷歌搜索找到任何与此相关的内容,所以我希望您有任何建议或解决此问题的经验。
I'm having trouble disconnecting from a ftp-server, using the enterprisedt java ftp framework.
I can simply not call disconnect() on a FileTransferClient object without getting an error.
I do not do anything, besides connecting to the server, and then disconnecting:
// create client
log.info("Creating FTP client");
ftp = new FileTransferClient();
// set remote host
log.info("Setting remote host");
ftp.setRemoteHost(host);
ftp.setUserName(username);
ftp.setPassword(password);
// connect to the server
log.info("Connecting to server " + host);
ftp.connect();
log.info("Connected and logged in to server " + host);
// Shut down client
log.info("Quitting client");
ftp.disconnect();
log.info("Example complete");
When running this, the log reads:
INFO [test] 28 maj 2010 16:57:20.216 : Creating FTP client
INFO [test] 28 maj 2010 16:57:20.263 : Setting remote host
INFO [test] 28 maj 2010 16:57:20.263 : Connecting to server x
INFO [test] 28 maj 2010 16:57:20.979 : Connected and logged in to server x
INFO [test] 28 maj 2010 16:57:20.979 : Quitting client
ERROR [FTPControlSocket] 28 maj 2010 16:57:21.026 : Read failed ('' read so far)
And the stacktrace:
com.enterprisedt.net.ftp.ControlChannelIOException: Connection reset
at com.enterprisedt.net.ftp.FTPControlSocket.readLine(FTPControlSocket.java:1029)
at com.enterprisedt.net.ftp.FTPControlSocket.readReply(FTPControlSocket.java:1089)
at com.enterprisedt.net.ftp.FTPControlSocket.sendCommand(FTPControlSocket.java:988)
at com.enterprisedt.net.ftp.FTPClient.quit(FTPClient.java:4044)
at com.enterprisedt.net.ftp.FileTransferClient.disconnect(FileTransferClient.java:1034)
at test.main(test.java:46)
It should be noted, that I without problems can connect, and do stuff with the server, like getting a list of files in the current working directory. But I cant, for some reason, disconnect! I've tried using both active and passive mode.
The above example is by the way copy/pasted from their own example. I cannot fint ANYTHING related to this by doing a Google-search, so I was hoping you have any suggestions, or experience with this issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试启用跟踪,
这将使您观察库和 ftp 服务器之间的通信。
尝试使用命令行客户端打开与 ftp 服务器的连接。连接、登录、验证一切正常。然后输入
quot quit
。这会向 ftp 服务器发送显式的quit
命令。您应该收到221
或226
响应。如果您收到任何其他代码,或者连接刚刚关闭,那么您将遇到不兼容的 FTP 服务器。如果是这种情况,您还可以尝试使用
disconnect(true)
因为它只是关闭连接,而不是尝试正常关闭。Try enabling the traces with
That will let you observe the communication between the library and the ftp server.
Try opening a connection to the ftp server with a command line client. Connect, log in, verify that is all working. Then type
quot quit
. That sends an explicitquit
command to the ftp server. You should get either a221
or a226
response. If you get any other code, or if the connection is just closed, then you're up against a non-compliant FTP server.If that's the case, you can also try using
disconnect(true)
as that just closes connections rather than attempting a graceful shutdown.