Sunday, 15 July 2012

java - ftp connection to determine if file is there -



java - ftp connection to determine if file is there -

i trying check if file exist in ftp. when testing 1 user seems fine. scenario of multiple users seems throw below exception : exception in thread "main" sun.net.ftp.ftpprotocolexception: welcome message: 421.

below code utilize check if file there , have closed connection still throws sun.net.ftp.ftpprotocolexception:welcome message: 421.

public boolean getftpfileexists(string fileurl) { url theurl = null; inputstream inputstream = null; ftpurlconnection ftpurlconn = null; boolean ftpfileexists = false; seek { theurl = new url(fileurl); ftpurlconn = (ftpurlconnection)theurl.openconnection(); inputstream = ftpurlconn.getinputstream();//calling method throw 'filenotfoundexception' if doesn't exist ftpfileexists = true; } catch(filenotfoundexception fnfe) { ftpfileexists = false; } catch(exception e) { system.out.println(e.tostring()); ftpfileexists = false;//hmm, not sure really! } { //close inputstream & connection if(inputstream != null) { seek { inputstream.close(); } catch(ioexception ioe) { system.out.println("error closing input stream: "+ioe.getmessage()); } } seek { ftpurlconn.close(); } catch(exception e) { system.out.println("error closing ftpurlconnection"); } } homecoming ftpfileexists; }

could help me please?

can recreate error ?

at case:

by error msg:

421: service not available, closing command connection. may reply command if service knows must shut down.

it sounds maybe there's configuration needs done @ ftpserver rather code error.

java file url connection

No comments:

Post a Comment