2014-10-06 41 views
0

我試圖檢查文件是否存在於FTP中。當用一個用戶測試時,它似乎很好。但是對於多個用戶的情況,它似乎會拋出以下異常: 線程「main」中的異常sun.net.ftp.FtpProtocolException:歡迎信息:421.通過ftp連接來確定文件是否存在

下面是我們用來檢查文件在那裏,我們已經關閉所有的連接,但它仍然拋出sun.net.ftp.FtpProtocolException:歡迎留言:421

public boolean getFtpFileExists(String fileUrl) 
    { 
    URL theURL = null; 
    InputStream inputStream = null; 
    FtpURLConnection ftpUrlConn = null; 
    boolean ftpFileExists = false; 

    try 
    { 
     theURL = new URL(fileUrl); 
     ftpUrlConn = (FtpURLConnection)theURL.openConnection(); 
     inputStream = ftpUrlConn.getInputStream();//calling this method will throw a '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! 
    } 
    finally 
    { 
     //close inputStream & connection 
     if(inputStream != null) 
     { 
     try 
     { 
      inputStream.close(); 
     } 
     catch(IOException ioe) 
     { 
      System.out.println("Error closing input stream: "+ioe.getMessage()); 
     } 
     } 

     try 
     { 
     ftpUrlConn.close(); 
     } 
     catch(Exception e) 
     { 
     System.out.println("Error closing ftpUrlConnection"); 
     } 
    } 

    return ftpFileExists; 
    } 

任何人都可以幫助我嗎?

+0

可能的重複[檢查是否存在使用java的「ftp」url](http://stackoverflow.com/questions/18316468/check-if-file-with-ftp-url-exists-using-java) – user2504380 2014-10-06 09:54:16

回答

0

你能重新創建你得到的錯誤嗎?

在任何情況下:

由誤差MSG:

421:服務不可用,關閉控制連接。這可能是 對任何命令的回覆,如果服務知道它必須關閉。

聽起來像是也許有一個配置需要在FTPServer完成,而不是代碼錯誤。