i want to send large files,,,,,this program only send upto size:1024*1024 ,,,,plz help me out!!
client-
import java.net.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class ftpclient extends JFrame implements ActionListener
{
JButton b1,b2;
JTextField t1;
ftpclient()
{
b1 =new JButton("Select File");
b2 = new JButton("Send File to Server");
t1 = new JTextField(15);
setLayout(new FlowLayout());
add(b1);
add(t1);
add(b2);
b1.addActionListener(this);
b2.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==b1)
{
FileDialog fd;
Frame f1=new Frame();
fd=new FileDialog(f1,"Select File");
fd.setSize(300,300);
fd.setVisible(true);
t1.setText(fd.getDirectory()+fd.getFile());
}
if(ae.getSource()==b2)
{
String s=t1.getText();
try
{
FileInputStream f1 = new FileInputStream(s);
byte b[]=new byte[1024*1024];
DataInputStream dis1 = new DataInputStream(f1);
Socket so = new Socket("127.0.0.1",20);
OutputStream os=so.getOutputStream();
dis1.read(b,0,b.length);
os.write(b);
os.flush();
so.close();
os.close();
}
catch(Exception e) { e.printStackTrace(); }
}
}
public static void main(String s[])
{
new ftpclient().setVisible(true);
}
}
server-
import java.io.*;
import java.net.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class ftpserver extends JFrame implements Runnable,ActionListener
{
TextArea t1; Thread t;
Button b1;
ftpserver()
{
t1=new TextArea();
add(t1);
b1=new Button("Save File");
b1.addActionListener(this);
add(b1,BorderLayout.SOUTH);
t=new Thread(this);
t.start();
}
byte b[] = new byte[1024*1024];
public void run()
{
try {
ServerSocket ss = new ServerSocket(20);
while(true)
{
Socket s = ss.accept();
System.out.println(s);
InputStream is = s.getInputStream();
is.read(b);
}
}catch(Exception e){e.printStackTrace(); }
}
public void actionPerformed(ActionEvent ae)
{
Frame f1=new Frame();
FileDialog fd = new FileDialog(f1,"Save",FileDialog.SAVE);
fd.setSize(300,300);
fd.setVisible(true);
try
{
FileOutputStream f=new FileOutputStream(fd.getDirectory()+fd.getFile());
f.write(b);
f.close();
}catch(Exception e){ }
}
public static void main(String s[])
{
new ftpserver().setVisible(true);
}
}