FtpClient problem
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Peter_Phung
Posted On:   Wednesday, February 13, 2002 03:50 AM

I'm writing an application which needs to check whether or not a directory exists on a FTP server. If it does not exist then i need to create the directory. At the moment i'm trying to check for the existing directory using a URLConnection object. Heres the code : url_ = new URL("ftp://birmha19/"+dir); try { URLConnection connect = url_.openConnection(); connect.connect(); taDisplay.appendText(" exists!!"); dex = 0; } catch (IOException urlex){ taDisplay.appendText(" not exists"); dex = 1; } The first problem is that t   More>>

I'm writing an application which needs to check whether or not a directory exists on a FTP server.

If it does not exist then i need to create the directory.
At the moment i'm trying to check for the existing directory using a URLConnection object.

Heres the code :



url_ = new URL("ftp://birmha19/"+dir);
try {

URLConnection connect = url_.openConnection();

connect.connect();

taDisplay.appendText("
exists!!");

dex = 0;

}

catch (IOException urlex){

taDisplay.appendText("
not exists");

dex = 1;

}



The first problem is that this piece of code always outputs exists.

Does anyone know of a solution to this problem?



The second problem is when i try to create a new directory on the FTP server, it's keeps returning errors,

e.g.

java.io.FileNotFoundException: MKD ./peterTest/508/BB99F55T/

: 550 ./peterTest/508/BB99F55T/: No such file or directory.



I'm using an extended version of sun.net.ftp.FtpClient(see below):



public class FClient extends FtpClient {



public FClient(String host) throws IOException{

super(host);

}



public void mkDir(String dir) {

try {

issueCommand("MKD "+dir+"
");

}

catch (IOException e) {

e.printStackTrace();

}

}

}



I don't know what the problem.

Can anyone please help?



Pete

   <<Less
About | Sitemap | Contact