Ftp connection
Hi for all
i created ftp class this class it connect to server and ubload files and downloading but have two problem
1.deleted method not run without compilation error
2.exsplorer method not run without compilation error
please any one tell me about this problem
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.net.MalformedURLException;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.File;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Vector;
publicclass FTPConnection
{
private URL url,urlDownload,urlUpload,urlRemove,urlExplorer;
private URLConnection connection,downloadConnection,uploadConnection;
private BufferedInputStream clintInput,downloadInput,uploadInput;
private PrintStream serverOutput,clientOutput,downloadOutput,uploadOutput;
private BufferedReader serverInput;
private Vector fileName;
private String inputLine;
private Integer counter;
private File listFiles;
public FTPConnection()
{
//No command execute
}
public FTPConnection(String urlConnection)
{
try
{
url=new URL(urlConnection);
}
catch(Exception e)
{
e.printStackTrace();
}
}
public FTPConnection(URL urlConnection,String urlFileName)
{
try
{
url=new URL(urlConnection+urlFileName);
}
catch(Exception e)
{
e.printStackTrace();
}
}
public FTPConnection(String userName,String password,String hostName)
{
try
{
url=new URL("ftp://" + userName +":" + password +"@" + hostName);
}
catch(Exception e)
{
e.printStackTrace();
}
}
publicboolean Connect()
{
try
{
connection=url.openConnection();
}
catch(Exception e)
{
returnfalse;
}
try
{
serverInput=new BufferedReader(new InputStreamReader(connection.getInputStream()));
serverOutput=new PrintStream(connection.getOutputStream());
returntrue;
}
catch(IOException e)
{
returnfalse;
}
}
publicboolean Connect(String urlConnection)
{
try{
url=new URL(urlConnection);
return Connect();
}
catch(Exception e)
{
returnfalse;
}
}
publicboolean Download(String file,String directory)
{
try
{
urlDownload=new URL(url,file);
}
catch(MalformedURLException mfue)
{
returnfalse;
}
try
{
downloadConnection=urlDownload.openConnection();
downloadInput=new BufferedInputStream(downloadConnection.getInputStream());
downloadOutput=new PrintStream(directory +"\\" + file);
int i = 0;
byte[] bytesIn =newbyte[downloadInput.available()];
while ((i = downloadInput.read(bytesIn)) >= 0){
downloadOutput.write(bytesIn, 0, i);
}
downloadOutput.close();
downloadInput.close();
returntrue;
}
catch(IOException e)
{
returnfalse;
}
}
publicboolean Upload(String file,String directory)
{
try
{
urlUpload=new URL(url,file);
}
catch(MalformedURLException mfue)
{
returnfalse;
}
try
{
uploadConnection=urlUpload.openConnection();
uploadInput=new BufferedInputStream(new FileInputStream(directory +"\\" + file));
uploadOutput=new PrintStream(uploadConnection.getOutputStream());
if (uploadInput.available()!=0){
int i = 0;
byte[] bytesIn =newbyte[uploadInput.available()];
while ((i = uploadInput.read(bytesIn)) >= 0){
uploadOutput.write(bytesIn, 0, i);
}}
uploadOutput.close();
uploadInput.close();
returntrue;
}
catch(IOException ioe)
{
returnfalse;
}
}
public Vector Explorer()
{
try//this method to return the all files in Server as vector but it no work
{
File listFiles=new File(url.getUserInfo()+"@"+url.getHost()+"/");
}
catch(Exception murl)
{
murl.printStackTrace();
returnnull;
}
System.out.println(url.getUserInfo()+"@"+url.getHost());
String listOfFiles[]=listFiles.list();
for (int i=0;i<listOfFiles.length;i++)
{
System.out.println(listOfFiles[i].toString());
fileName.add(listOfFiles[i].toString());
}
return fileName;
}
publicvoid Remove(String fileName)//it method to delete the file on server but not work
{
try
{
urlRemove=new URL(url,fileName);
}
catch(MalformedURLException murl){}
try
{
File file=new File(urlRemove.getFile());
System.out.println(urlRemove.getFile());
file.delete();
}
catch(Exception oie){oie.printStackTrace();}
}
}
thanks

