File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Applets and the fly likes problems in FTP socket in an applet Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Applets
Reply Bookmark "problems in FTP socket in an applet" Watch "problems in FTP socket in an applet" New topic
Author

problems in FTP socket in an applet

Manimala Kumar
Greenhorn

Joined: May 24, 2001
Posts: 1
Hello everybody,
I'm doing a project on mail client system. For remote users i need a ftp of the required file. I am running BRS WebWeaver in my pc and if I try from other pc's with anonymous ftp(i.e. ftp 10.101.1.96 etc.),then it works. But as soon as I try it with my socket initially it flashes a ready message and after that it automatically gets disconnected. So I'm unable to send further commands.
If anybody knows it, please help me. I'm appending my progs here.
Manimala.

//applet code
import java.applet.*;
import java.awt.*;
import java.io.*;
import java.awt.event.*;
import java.util.*;
import java.net.*;
import javax.swing.*;
public class japp extends Applet implements ActionListener
{
String attach = null;
Socket localSocket;
PrintWriter outbnd;
BufferedReader inbnd;
String s;
private Button b;
String line = null;
private TextField t2;
public void init()
{
setLayout(new FlowLayout());
attach = getParameter("c"); //get file name with full path from prev text box
t2 = new TextField(60);
add(t2);
b = new Button("Connect");
b.addActionListener(this);
add(b);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == b) //Create a socket
try
{
t2.setText(attach);
localSocket = new Socket("10.101.1.96",21); //Setup data
inbnd = new BufferedReader(new InputStreamReader (localSocket.getInputStream()));
outbnd= new PrintWriter(localSocket.getOutputStream());
//While we have a connection
//Read Texfield value
// read incoming string from socket
line = inbnd.readLine();
t2.setText(line);
outbnd.println("anonymous");
outbnd.flush();
line = inbnd.readLine();
t2.setText(line);
outbnd.println("mani@lycos.com");
outbnd.flush();
line = inbnd.readLine();
t2.setText(line);
outbnd.println("get "+attach);
outbnd.flush();
line = inbnd.readLine();
t2.setText(line);
outbnd.println("bye ");
outbnd.flush();
outbnd.close();
inbnd.close();
localSocket .close();
}
catch(UnknownHostException unc)
{
System.out.println("Connection why not connected");
}
catch(IOException ioe)
{
System.out.println(ioe.getMessage());
}
}
public static void main( String[] args )//without/with it's ok
{
netappsock applet = new netappsock();
JFrame frame = new JFrame();
frame.setTitle( "Socket Test" );
frame.getContentPane().add( applet , BorderLayout.CENTER );
applet.init();
applet.start();
frame.setSize( 460 , 360 );
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation( ( d.width - frame.getSize().width ) / 2 ,( d.height - frame.getSize().height ) / 2 );
frame.setVisible( true );
}

}

//html code
<html>
<head></head>
<body>
<applet code=japp.class height=400 width=600>
<param name="c" value="C:\jdk1.3\bin\abcd.txt">
</applet>
</body>
</html>


------------------
prashant pachouri
Greenhorn

Joined: May 27, 2001
Posts: 12
If u are ready to do some change why not try serialized object communication. Read the file contents into a String. Open a socket connection, contruct an objectoutput stream and write the object to it.

Originally posted by Manimala Kumar:
Hello everybody,
I'm doing a project on mail client system. For remote users i need a ftp of the required file. I am running BRS WebWeaver in my pc and if I try from other pc's with anonymous ftp(i.e. ftp 10.101.1.96 etc.),then it works. But as soon as I try it with my socket initially it flashes a ready message and after that it automatically gets disconnected. So I'm unable to send further commands.
If anybody knows it, please help me. I'm appending my progs here.
Manimala.

//applet code
import java.applet.*;
import java.awt.*;
import java.io.*;
import java.awt.event.*;
import java.util.*;
import java.net.*;
import javax.swing.*;
public class japp extends Applet implements ActionListener
{
String attach = null;
Socket localSocket;
PrintWriter outbnd;
BufferedReader inbnd;
String s;
private Button b;
String line = null;
private TextField t2;
public void init()
{
setLayout(new FlowLayout());
attach = getParameter("c"); //get file name with full path from prev text box
t2 = new TextField(60);
add(t2);
b = new Button("Connect");
b.addActionListener(this);
add(b);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == b) //Create a socket
try
{
t2.setText(attach);
localSocket = new Socket("10.101.1.96",21); //Setup data
inbnd = new BufferedReader(new InputStreamReader (localSocket.getInputStream()));
outbnd= new PrintWriter(localSocket.getOutputStream());
//While we have a connection
//Read Texfield value
// read incoming string from socket
line = inbnd.readLine();
t2.setText(line);
outbnd.println("anonymous");
outbnd.flush();
line = inbnd.readLine();
t2.setText(line);
outbnd.println("mani@lycos.com");
outbnd.flush();
line = inbnd.readLine();
t2.setText(line);
outbnd.println("get "+attach);
outbnd.flush();
line = inbnd.readLine();
t2.setText(line);
outbnd.println("bye ");
outbnd.flush();
outbnd.close();
inbnd.close();
localSocket .close();
}
catch(UnknownHostException unc)
{
System.out.println("Connection why not connected");
}
catch(IOException ioe)
{
System.out.println(ioe.getMessage());
}
}
public static void main( String[] args )//without/with it's ok
{
netappsock applet = new netappsock();
JFrame frame = new JFrame();
frame.setTitle( "Socket Test" );
frame.getContentPane().add( applet , BorderLayout.CENTER );
applet.init();
applet.start();
frame.setSize( 460 , 360 );
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation( ( d.width - frame.getSize().width ) / 2 ,( d.height - frame.getSize().height ) / 2 );
frame.setVisible( true );
}

}

//html code
<html>
<head></head>
<body>
<applet code=japp.class height=400 width=600>
<param name="c" value="C:\jdk1.3\bin\abcd.txt">
</applet>
</body>
</html>



If you are not living on the edge, you are wasting Space.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: problems in FTP socket in an applet
 
Similar Threads
What's wrong here!
Client Applet- server application
What's wrong here!
What is wrong here!
Successful Applet Socket Connection