Date: 2004-06-08T04:10:41
Editor: 217.204.110.30 <>
Wiki: Jakarta Commons Wiki
Page: Net/FrequentlyAskedQuestions
URL: http://wiki.apache.org/jakarta-commons/Net/FrequentlyAskedQuestions
no comment
New Page:
This document attempts to answer some of the more frequently asked questions regarding
various aspects of CommonsNet. These questions are typically asked over and over again
on the mailing lists, as a courtesy to the developers, we ask that you read this
document before posting to the mailing lists.
----
'''Q: On which server operating systems is FTPClient able to bring back a parsed
listing?'''
'''A:''' Currently parsers have been written for UNIX, NT, OS/2 and VMS. When version
1.2.0 is released these will be able to be autodetected
by the code without being specified. In version 1.2.0 there will also be included a
means of specifying a user-written parser by class name. All of these parsers return
FTPFile objects with as much information about the file as can be gathered from the
listing.
If none of these is sufficient, FTPClient.listNames() may always be called. This
retrieves just the file name without other information.
----
'''Q: Why are my files corrupt after transfer?'''
'''A:''' The most common cause for this is when the file is transfered as ASCII but
the contents of the file are not ASCII and the file should be transferred as BINARY.
RFC 959 says the default transfer mode should be ASCII. FTPClient conforms to the
standard. You must explicitly call <pre>setFileType(FTP.BINARY_FILE_TYPE);</pre> to
request binary transfer mode after logging in to the FTP server.
----
'''Q: How do I get passive mode correctly started?'''
'''A:''' Passive mode has to be established each time you connect to an FTP server.
After you connect to a server with <code>FTPClient.connect()</code>, you can call
<code>FTPClient.enterLocalPassiveMode()</code> to enable passive mode. From then
on, FTPClient will take care of issuing a PASV command each time it opens a data
connection until you change the data connection mode by calling
<code>enterLocalActiveMode()</code> or you close the connection. If you call
<code>enterLocalPassiveMode</code> before connecting to a server, the data
connection mode will be reset to the default active mode upon initial connection
establishment. If you always want to use passive mode and don't want to call
<code>enterLocalPassiveMode</code> all the time, you can subclass FTPClient and
override
<code>_connectAction_()</code> like so:
<pre>
protected void _connectAction_() throws IOException {
super._connectAction_();
enterLocalPassiveMode();
}
</pre>
----
'''Q: Using the NNTPClient, retrieving a list of headers takes forever. Why is that?'''
Normal retrieval of headers using a program like Grabit takes about 10 seconds for a
group containing about 3000 articles. This piece of code takes about 2 minutes. All
the time, the network is hardly used. How can it be fixed?
<pre>
try
{
Date startTime = new Date();
log.debug("Connecting to " + host + "...");
client.connect(host);
client.setTcpNoDelay(true);
NewsgroupInfo info = new NewsgroupInfo();
int articles = 0
if (client.selectNewsgroup(group, info))
{
articles = info.getArticleCount();
log.debug(group + " selected. Contains " + articles + " articles.");
}
Reader r = null;
BufferedReader rr = null;
for (int i = start; i <= end; i++)
{
r = client.retrieveArticleHeader(i);
if (r != null)
{
rr = new BufferedReader(r);
String header = "";
while (rr.ready())
header += rr.readLine() + "\n";
}
}
client.disconnect();
log.debug("Disconnected.");
Date endTime = new Date();
long update = (endTime.getTime() - startTime.getTime())/1000;
if (update < 60)
log.info("Update took " + update + " seconds.");
else
log.info("Update took " + update/60 + " minute(s).");
}
catch (IOException e)
{
log.error(e);
}
</pre>
'''A:''' After some thinking and browsing of the Commons-Net sourcecode, I come to the
conclusion that the reason why updating all headers is so slow, is the fact that each
message header is retrieved separately with a new command send to the server each
time.
'''Update:''' This is indeed an issue. There are two fixes which I hope to implement -
one is the utilisation of an extended NNTP command like XOVER or XHDR to retrieve the
info, the other is the most useful one - actually taking a look at the parsing code
and seeing where we can optimise that. I am confident we can improve the efficiency by
a great deal - there is a lot of String creation in the internal reply parsing
routines. - RoryWinston
'''UPDATE:''' Rory's patch to include XOVER was applied in August or September 2003.
----
'''Q: Are the Commons-Net classes thread-safe? For example, can you have multiple
instances of FTPClient, each with its own thread running inside?'''
'''A:''' Multiple instances of FTPClient can be used to connect to multiple (or the
same) FTP server
and concurrently retrieve files. If you want to share a single FTPClient instance
between multiple
threads, you must serialize access to the object with critical sections.
----
'''Q: Does the SMTP client support ESMTP functions? Does it support RFC2821, RFC2822,
RFC2487 TLS, RFC2554 authentication, RFC2920 command pipelining, RFC3030 large/binary
messages, etc.?'''
----
'''Q: Does FTPClient support FTP connections through an FTP proxy server?'''
'''A:''' Paul Buchanan answers this question here:
http://marc.theaimsgroup.com/?l=jakarta-commons-user&m=107877944806547&w=2
The summary is:
<pre>
Since the Net project uses java.net.Socket under the covers, you have to set
up the Socket settings. If the proxy you are using is a SOCKS4 or SOCKS5
proxy, you can set the following System Properties:
System.getProperties().put( "socksProxyPort", "1080");
System.getProperties().put( "socksProxyHost" ,"proxy.host.address");
>From what I can tell, 1080 is the default port for SOCKS proxies. The
following site documents many of the networking System Properties available:
http://java.sun.com/j2se/1.4.2/docs/guide/net/properties.html
</pre>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]