wood burning stoves 2.0*
The moose likes Sockets and Internet Protocols and the fly likes ask .change ftptransfer mode Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "ask .change ftptransfer mode " Watch "ask .change ftptransfer mode " New topic
Author

ask .change ftptransfer mode

do jin kim
Greenhorn

Joined: Nov 16, 2012
Posts: 3
import java.net.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.lang.*;
class FtpClient extends JFrame implements ActionListener
{
String fn,filenm;
String fc;
String dirn="c:/FTP CLIENT DIRECTORY";
JPanel pnl;
JLabel lbltle,lblud;
Font fnt;
JTextField txtfn;
JButton btnu,btnd;
Socket s;
InputStreamReader in;
OutputStream out;
BufferedReader br;
PrintWriter pw;
public FtpClient()
{
super("FTP CLIENT");

pnl=new JPanel(null);

fnt=new Font("Times New Roman",Font.BOLD,25);

lbltle=new JLabel("FTP CLIENT");
lbltle.setFont(fnt);
lbltle.setBounds(225,35,200,30);
pnl.add(lbltle);

lblud=new JLabel("ENTER FILE-NAME :");
lblud.setBounds(100,100,150,35);
pnl.add(lblud);

txtfn=new JTextField();
txtfn.setBounds(300,100,200,25);
pnl.add(txtfn);

btnu=new JButton("UPLOAD");
btnu.setBounds(150,200,120,35);
pnl.add(btnu);


btnd=new JButton("DOWNLOAD");
btnd.setBounds(320,200,120,35);

pnl.add(btnd);

btnu.addActionListener(this);
btnd.addActionListener(this);
getContentPane().add(pnl);

try
{
s=new Socket("localhost",100);
br=new BufferedReader(new InputStreamReader(s.getInputStream()));
pw=new PrintWriter(s.getOutputStream(),true);
out=s.getOutputStream();
}
catch(Exception e)
{
System.out.println("ExCEPTION :"+e.getMessage());
}
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==btnu)
{
try
{
filenm=txtfn.getText();
pw.println(filenm);
FileInputStream fis=new FileInputStream(filenm);
byte[] buffer=new byte[1024];
int bytes=0;

while((bytes=fis.read(buffer))!=-1)
{
out.write(buffer,0,bytes);
}
fis.close();
}
catch(Exception exx)
{
System.out.println(exx.getMessage());
}
}

if(e.getSource()==btnd)
{
try
{
File dir=new File(dirn);
if(!dir.exists())
{
dir.mkdir();
}
else{}
boolean done=true;
filenm=txtfn.getText();
fn=new String("#"+filenm+"#");
//System.out.println(filenm);
pw.println(fn);
File f=new File(dir,filenm);
FileOutputStream fos=new FileOutputStream(f);
DataOutputStream dops=new DataOutputStream(fos);
while(done)
{
fc=br.readLine();
if(fc==null)
{
done=false;
}
else
{
dops.writeChars(fc);
// System.out.println(fc);

}
}
fos.close();
}

catch(Exception exx)
{}

}
}
public static void main(String args[])
{
FtpClient ftpc=new FtpClient();
ftpc.setSize(600,300);
ftpc.show();
}
}


can anyone help me where must i change those code so that it can run in binary mode ?? those code run in ascii mode and utf-8 unicode .should i change the unicode too .
Richard Tookey
Ranch Hand

Joined: Aug 27, 2012
Posts: 1084
    
  10

That code seems to have been lifted from http://ubuntuforums.org/archive/index.php/t-1847606.html .
do jin kim
Greenhorn

Joined: Nov 16, 2012
Posts: 3
http://www.123eng.com/sourcecode/java/networking/ftp-server.html too .
but if i wanna change transfer mode into binary, how is it ??
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2510
    
  10

You can send the 'bin' command to the server before activating the transfer.

OCUP UML fundamental and ITIL foundation
youtube channel
do jin kim
Greenhorn

Joined: Nov 16, 2012
Posts: 3
give me example please .i'm new in learnin java .so i'm looking for help from master2 here ^^
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2510
    
  10

There are quite some java open source ftp clients. Check how they implement the same problem you have.

In your exercise, do you want to focus on the ftp functionality, or are you focusing on GUI? In the second case, it might be easier to use an ftp library in stead of starting from scratch using the core java libraries.
Good luck, Jan
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: ask .change ftptransfer mode