🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.jbuilder.java.language
2 messages
2 total messages Started by congzb Fri, 17 Feb 2006 10:48
ftp client
#229
Author: congzb
Date: Fri, 17 Feb 2006 10:48
59 lines
2307 bytes
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
Re: ftp client
#230
Author: Lori M Olson [TeamB]
Date: Fri, 17 Feb 2006 17:17
88 lines
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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads