Article View: borland.public.jbuilder.java.language
Article #230Re: ftp client
From: Lori M Olson [TeamB]
Date: Fri, 17 Feb 2006 17:17
Date: Fri, 17 Feb 2006 17:17
88 lines
3400 bytes
3400 bytes
congzb wrote:
> hello all
> see my program following:
>
> public static void main(String args[]) {
> Socket socket = null;
> BufferedReader in = null;
> PrintWriter out = null;
> String line = null;
>
> try {
> socket = new Socket("myserver", 21);
> in = new BufferedReader(new InputStreamReader(socket
> .getInputStream()));
> out = new PrintWriter(socket.getOutputStream());
> out.println("user " + "congzb");
> out.println("pass " + "1qazxsw2");
> out.println("pwd");
>
>
> out.println("pasv");
> out.println("list");
>
> out.println("quit");
> out.flush();
>
> while ((line = in.readLine()) != null) {
> System.out.println(line);
> }
>
> } catch (Exception e) {
> System.out.println(e.getMessage());
> } finally {
> try {
> out.close();
> in.close();
> socket.close();
> } catch (Exception fe) {
> System.out.println("RESOURCE CLOSE EXCEPTION "
> + fe.getMessage());
> }
> }
> }
>
>
>
> the trace info as following:
>
> 331 Password required for congzb.
> 230-Last unsuccessful login: Fri Feb 17 02:21:26 EST 2006 on /dev/pts/1 from 9.186.23.101
> 230-Last login: Fri Feb 17 05:59:26 EST 2006 on ftp from ::ffff:9.186.23.101
> 230 User congzb logged in.
> 257 "/home/congzb" is current directory.
> 227 Entering Passive Mode (9,56,249,42,152,101)
>
>
> in fact, it hang on "pasv" command. and don't give me the answer of "list" command.
>
> why? thanks
You need to have a PrintWriter for the socket error stream, as well as
the output stream, or else you won't see any errors.
Also, you might get into some problems, because failure to promptly read
from or write to those streams may cause them to block or deadlock.
The #2 posting on this page offers some guidance on the blocking issues.
http://java.ittoolbox.com/documents/popular-q-and-a/removing-the-dos-prompt-1773
--
Regards,
Lori Olson [TeamB]
------------
Save yourself, and everyone else, some time and search the
newsgroups and the FAQ-O-Matic before posting your next
question.
Google Advanced Newsgroup Search
http://www.google.ca/advanced_group_search
Other Newsgroup Searches:
http://www.borland.com/newsgroups/ngsearch.html
Joi Ellis's FAQ-O-Matic:
http://www.visi.com/~gyles19/fom-serve/cache/1.html
Technical Details
Message-ID:
<43f6043f$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!news-peer0-test!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<43f5b81b$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: f74b3,8ff86596ca28d3bf X-Google-Attributes: gidf74b3,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Fri, 17 Feb 2006 10:17:48 -0700 From: "Lori M Olson [TeamB]" <javadragon@techie.com> User-Agent: Thunderbird 1.5 (Macintosh/20051201) MIME-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language Subject: Re: ftp client References: <43f5b81b$1@newsgroups.borland.com> In-Reply-To: <43f5b81b$1@newsgroups.borland.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 142.179.182.172 Message-ID: <43f6043f$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1140196415 142.179.182.172 (17 Feb 2006 09:13:35 -0700) Lines: 88 Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!news-peer0-test!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail