[英]ftp connection to determine if file is there
我正在尝试检查FTP中是否存在该文件。 当与一个用户进行测试时,这似乎很好。 但是在有多个用户的情况下,似乎抛出以下异常:线程“ main”中的异常sun.net.ftp.FtpProtocolException:欢迎消息:421。
下面是用于检查文件是否存在的代码,我们已经关闭了所有连接,但仍然抛出sun.net.ftp.FtpProtocolException:Welcome消息: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;
}
有人可以帮我吗?
您可以重现所得到的错误吗?
在任何情况下:
错误MSG:
421:服务不可用,正在关闭控制连接。 如果服务知道它必须关闭,则可能是对任何命令的答复。
听起来好像需要在FTPServer上进行配置而不是代码错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.