Java Code Examples for org.apache.commons.net.ftp.ftpclient#disconnect()

The following examples show how to use org.apache.commons.net.ftp.ftpclient#disconnect() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FTPUploader.java    From azure-gradle-plugins with MIT License 6 votes vote down vote up
/**
 * Upload directory to specified FTP server without retries.
 *
 * @param ftpServer
 * @param username
 * @param password
 * @param sourceDirectoryPath
 * @param targetDirectoryPath
 * @return Boolean to indicate whether uploading is successful.
 */
protected boolean uploadDirectory(final String ftpServer, final String username, final String password,
                                  final String sourceDirectoryPath, final String targetDirectoryPath) {
    logger.debug("FTP username: " + username);
    try {
        final FTPClient ftpClient = getFTPClient(ftpServer, username, password);

        logger.quiet(String.format(UPLOAD_DIR_START, sourceDirectoryPath, targetDirectoryPath));
        uploadDirectory(ftpClient, sourceDirectoryPath, targetDirectoryPath, "");
        logger.quiet(String.format(UPLOAD_DIR_FINISH, sourceDirectoryPath, targetDirectoryPath));

        ftpClient.disconnect();
        return true;
    } catch (Exception e) {
        logger.error(String.format(UPLOAD_DIR_FAILURE, sourceDirectoryPath, targetDirectoryPath), e);
    }

    return false;
}
 
Example 2
Source File: MultipleConnectionTestCase.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
@Test
public void testUnderlyingConnect() throws SocketException, IOException {
    final FTPClient client1 = new FTPClient();
    final FTPClient client2 = new FTPClient();
    try {
        final String hostname = "localhost";
        client1.connect(hostname, FtpProviderTestCase.getSocketPort());
        client2.connect(hostname, FtpProviderTestCase.getSocketPort());
    } finally {
        if (client1 != null) {
            client1.disconnect();
        }
        if (client2 != null) {
            client2.disconnect();
        }
    }
}
 
Example 3
Source File: FtpUtils.java    From kkFileView with Apache License 2.0 6 votes vote down vote up
public static void download(String ftpUrl, String localFilePath, String ftpUsername, String ftpPassword, String ftpControlEncoding) throws IOException {
    String username = StringUtils.isEmpty(ftpUsername) ? ConfigConstants.getFtpUsername() : ftpUsername;
    String password = StringUtils.isEmpty(ftpPassword) ? ConfigConstants.getFtpPassword() : ftpPassword;
    String controlEncoding = StringUtils.isEmpty(ftpControlEncoding) ? ConfigConstants.getFtpControlEncoding() : ftpControlEncoding;
    URL url = new URL(ftpUrl);
    String host = url.getHost();
    int port = (url.getPort() == -1) ? url.getDefaultPort() : url.getPort();
    String remoteFilePath = url.getPath();
    LOGGER.debug("FTP connection url:{}, username:{}, password:{}, controlEncoding:{}, localFilePath:{}", ftpUrl, username, password, controlEncoding, localFilePath);
    FTPClient ftpClient = connect(host, port, username, password, controlEncoding);
    OutputStream outputStream = new FileOutputStream(localFilePath);
    ftpClient.enterLocalPassiveMode();
    boolean downloadResult = ftpClient.retrieveFile(new String(remoteFilePath.getBytes(controlEncoding), StandardCharsets.ISO_8859_1), outputStream);
    LOGGER.debug("FTP download result {}", downloadResult);
    outputStream.flush();
    outputStream.close();
    ftpClient.logout();
    ftpClient.disconnect();
}
 
Example 4
Source File: FTPClientFactory.java    From hsweb-framework with Apache License 2.0 6 votes vote down vote up
public PooledObject<FTPClient> makeObject() throws Exception {
    FTPClient ftpClient = new FTPClient();
    ftpClient.setConnectTimeout(config.getClientTimeout());
    ftpClient.connect(config.getHost(), config.getPort());
    int reply = ftpClient.getReplyCode();
    if (!FTPReply.isPositiveCompletion(reply)) {
        ftpClient.disconnect();
        logger.warn("FTPServer refused connection");
        return null;
    }
    boolean result = ftpClient.login(config.getUsername(), config.getPassword());
    if (!result) {
        throw new ConnectException("ftp登陆失败:" + config.getUsername() + "/password:" + config.getPassword() + "@" + config.getHost());
    }
    ftpClient.setFileType(config.getTransferFileType());
    ftpClient.setBufferSize(1024);
    ftpClient.setControlEncoding(config.getEncoding());
    if (config.isPassiveMode()) {
        ftpClient.enterLocalPassiveMode();
    }
    return new DefaultPooledObject<>(ftpClient);

}
 
Example 5
Source File: FTPUtil.java    From seed with Apache License 2.0 6 votes vote down vote up
/**
 * 登出FTP服务器
 * <p>
 *     由于本工具类会自动维护FTPClient连接,故调用该方法便可直接登出FTP
 * </p>
 */
public static void logout(){
    FTPClient ftpClient = ftpClientMap.get();
    ftpClientMap.remove();
    if(null != ftpClient){
        String ftpRemoteAddress = ftpClient.getRemoteAddress().toString();
        try{
            ftpClient.logout();
            LogUtil.getLogger().debug("FTP服务器[" + ftpRemoteAddress + "]登出成功...");
        }catch (IOException e){
            LogUtil.getLogger().warn("FTP服务器[" + ftpRemoteAddress + "]登出时发生异常,堆栈轨迹如下", e);
        }finally{
            if(ftpClient.isConnected()){
                try {
                    ftpClient.disconnect();
                    LogUtil.getLogger().debug("FTP服务器[" + ftpRemoteAddress + "]连接释放完毕...");
                } catch (IOException ioe) {
                    LogUtil.getLogger().warn("FTP服务器[" + ftpRemoteAddress + "]连接释放时发生异常,堆栈轨迹如下", ioe);
                }
            }
        }
    }
}
 
Example 6
Source File: AppServiceTest.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
/**
 * Uploads a file to an Azure web app.
 * @param profile the publishing profile for the web app.
 * @param fileName the name of the file on server
 * @param file the local file
 */
public static void uploadFileToWebApp(PublishingProfile profile, String fileName, InputStream file) {
    FTPClient ftpClient = new FTPClient();
    String[] ftpUrlSegments = profile.ftpUrl().split("/", 2);
    String server = ftpUrlSegments[0];
    String path = "./site/wwwroot/webapps";
    if (fileName.contains("/")) {
        int lastslash = fileName.lastIndexOf('/');
        path = path + "/" + fileName.substring(0, lastslash);
        fileName = fileName.substring(lastslash + 1);
    }
    try {
        ftpClient.connect(server);
        ftpClient.login(profile.ftpUsername(), profile.ftpPassword());
        ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
        for (String segment : path.split("/")) {
            if (!ftpClient.changeWorkingDirectory(segment)) {
                ftpClient.makeDirectory(segment);
                ftpClient.changeWorkingDirectory(segment);
            }
        }
        ftpClient.storeFile(fileName, file);
        ftpClient.disconnect();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example 7
Source File: FtpUtils.java    From carina with Apache License 2.0 5 votes vote down vote up
public static void ftpDisconnect(FTPClient ftp) {
    try {
        if (ftp.isConnected()) {
            try {
                ftp.logout();
                ftp.disconnect();
            } catch (Exception ioe) {
                LOGGER.error("Exception while disconnecting ftp", ioe);
            }
        }
    } catch (Throwable thr) {
        LOGGER.error("Throwable while disconnecting ftp", thr);
    }
    LOGGER.debug("FTP has been successfully disconnected.");
}
 
Example 8
Source File: FtpUtil.java    From util with Apache License 2.0 5 votes vote down vote up
/** 
 * 从FTP服务器列出指定文件夹下文件名列表。 
 * @param remotePath FTP服务器上的相对路径 
 * @return List<String> 文件名列表,如果出现异常返回null。
 * @throws IOException 
 */  
public List<String> getFileNameList(String remotePath) throws IOException {  
	//目录列表记录
       List<String> fileNames=new ArrayList<String>();
    FTPClient ftp = new FTPClient();  
    try {  
        int reply;  
        ftp.connect(url, port);  
        //如果采用默认端口,可以使用ftp.connect(url)的方式直接连接FTP服务器  
        ftp.login(userName, password);//登录  
        reply = ftp.getReplyCode();  
        if (!FTPReply.isPositiveCompletion(reply)) {  
            ftp.disconnect();  
            return null;  
        }  
        ftp.changeWorkingDirectory(remotePath);//转移到FTP服务器目录  
        FTPFile[] fs = ftp.listFiles();
        for(FTPFile file : fs){
        	fileNames.add(file.getName());
        }  
        ftp.logout();  
    } catch (IOException e) { 
        e.printStackTrace();  
        throw e ;
    } finally {  
        if (ftp.isConnected()) {  
            try {  
                ftp.disconnect();  
            } catch (IOException ioe) {  
            }  
        }  
    }
    return fileNames;
}
 
Example 9
Source File: FTPDropbox2Publisher.java    From datasync with MIT License 5 votes vote down vote up
/**
 * Closes the given FTPS connection (if one is open)
 *
 * @param ftp authenticated ftps object
 */
private static void closeFTPConnection(FTPClient ftp) {
    if(ftp.isConnected()) {
        try {
            ftp.logout();
            ftp.disconnect();
        } catch(IOException ioe) {
            // do nothing
        }
    }
}
 
Example 10
Source File: FTPServerTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Simple negative test that connects to the inbuilt ftp server and attempts to 
 * log on with the wrong password.
 * 
 * @throws Exception
 */
public void testFTPConnectNegative() throws Exception
{
    logger.debug("Start testFTPConnectNegative");

    FTPClient ftp = connectClient();

    try
    {
        int reply = ftp.getReplyCode();

        if (!FTPReply.isPositiveCompletion(reply))
        {
            fail("FTP server refused connection.");
        }
    
        boolean login = ftp.login(USER_ADMIN, "garbage");
        assertFalse("admin login successful", login);
        
        // now attempt to list the files and check that the command does not 
        // succeed
        FTPFile[] files = ftp.listFiles();
        
        assertNotNull(files);
        assertTrue(files.length == 0);
        reply = ftp.getReplyCode();
        
        assertTrue(FTPReply.isNegativePermanent(reply));
        
    } 
    finally
    {
        ftp.disconnect();
    }       
}
 
Example 11
Source File: FTPClientTemplate.java    From MicroCommunity with Apache License 2.0 5 votes vote down vote up
/** 
     * 断开ftp连接 
     *  
     * @throws Exception
     */  
    public void disconnect() throws Exception {
        try {  
            FTPClient ftpClient = getFTPClient();
//            ftpClient.logout();  
            if (ftpClient.isConnected()) {  
                ftpClient.disconnect();  
                ftpClient = null;  
            }  
        } catch (IOException e) {
            throw new Exception("Could not disconnect from server.", e);
        }  
    }
 
Example 12
Source File: FtpUtils.java    From kkFileView with Apache License 2.0 5 votes vote down vote up
public static FTPClient connect(String host, int port, String username, String password, String controlEncoding) throws IOException {
    FTPClient ftpClient = new FTPClient();
    ftpClient.connect(host, port);
    if (!StringUtils.isEmpty(username) && !StringUtils.isEmpty(password)) {
        ftpClient.login(username, password);
    }
    int reply = ftpClient.getReplyCode();
    if (!FTPReply.isPositiveCompletion(reply)) {
        ftpClient.disconnect();
    }
    ftpClient.setControlEncoding(controlEncoding);
    ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
    return ftpClient;
}
 
Example 13
Source File: FTPService.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
private static void close(FTPClient ftp) {
    if (ftp != null) {
        try {
            ftp.disconnect();
        } catch (Exception ignore) {
        }
    }
}
 
Example 14
Source File: TestCase.java    From springboot-ureport with Apache License 2.0 5 votes vote down vote up
/**
 * Description: 向FTP服务器上传文件
 * @Version1.0 Jul 27, 2008 4:31:09 PM by 崔红保([email protected])创建
 * @param url FTP服务器hostname
 * @param port FTP服务器端口
 * @param username FTP登录账号
 * @param password FTP登录密码
 * @param path FTP服务器保存目录
 * @param filename 上传到FTP服务器上的文件名
 * @param input 输入流
 * @return 成功返回true,否则返回false
 */
public static boolean uploadFile(String url,int port,String username, String password, String path, String filename, InputStream input) {
	boolean success = false;
	FTPClient ftp = new FTPClient();
	try {
		int reply;
		ftp.connect(url, port);//连接FTP服务器
		//如果采用默认端口,可以使用ftp.connect(url)的方式直接连接FTP服务器
		ftp.login(username, password);//登录
		reply = ftp.getReplyCode();
		if (!FTPReply.isPositiveCompletion(reply)) {
			ftp.disconnect();
			return success;
		}
		ftp.changeWorkingDirectory(path);
		ftp.storeFile(filename, input);			
		
		input.close();
		ftp.logout();
		success = true;
	} catch (IOException e) {
		e.printStackTrace();
	} finally {
		if (ftp.isConnected()) {
			try {
				ftp.disconnect();
			} catch (IOException ioe) {
			}
		}
	}
	return success;
}
 
Example 15
Source File: FTPClientFactory.java    From springboot-ureport with Apache License 2.0 5 votes vote down vote up
/**
	 * 创建一个FTPClient对象
	 */
	@Override
	public FTPClient makeObject() throws Exception {
		FTPClient ftpClient = new FTPClient();
//		ftpClient.setConnectTimeout(clientTimeout);
		ftpClient.connect(properties.getHostname(), properties.getPort());
		int replyCode = ftpClient.getReplyCode();
		if(!FTPReply.isPositiveCompletion(replyCode)){
			ftpClient.disconnect();
			log.warn("FTPServer 拒绝连接 !");
			return null;
		}
		boolean login = ftpClient.login(properties.getUsername(), properties.getPassword());
		if(!login){
			throw new FTPConnectionClosedException("FTPServer 登录失败!");
		}
//		ftpClient.setControlEncoding("UTF-8");
		FTPClientConfig conf = new FTPClientConfig(FTPClientConfig.SYST_NT);
		conf.setServerLanguageCode("zh");
		ftpClient.configure(conf);
		//ftpClient.setFileType(fileType);
//		ftpClient.setBufferSize(1024);
//		ftpClient.setControlEncoding(encoding);
//		if (passiveMode) {
//           ftpClient.enterLocalPassiveMode();
//        }

		return ftpClient;
	}
 
Example 16
Source File: FTPFileSystem.java    From hadoop-gpu with Apache License 2.0 5 votes vote down vote up
/**
 * Logout and disconnect the given FTPClient. *
 * 
 * @param client
 * @throws IOException
 */
private void disconnect(FTPClient client) throws IOException {
  if (client != null) {
    if (!client.isConnected()) {
      throw new FTPException("Client not connected");
    }
    boolean logoutSuccess = client.logout();
    client.disconnect();
    if (!logoutSuccess) {
      LOG.warn("Logout failed while disconnecting, error code - "
          + client.getReplyCode());
    }
  }
}
 
Example 17
Source File: FtpFileAdaptor.java    From xenon with Apache License 2.0 4 votes vote down vote up
@Override
public FileSystem createFileSystem(String location, Credential credential, Map<String, String> properties) throws XenonException {
    LOGGER.debug("newFileSystem ftp location = {} credential = {} properties = {}", location, credential, properties);

    if (location == null || location.isEmpty()) {
        throw new InvalidLocationException(ADAPTOR_NAME, "Location may not be empty");
    }

    if (credential == null) {
        throw new InvalidCredentialException(getName(), "Credential may not be null.");
    }

    if (!(credential instanceof PasswordCredential || credential instanceof DefaultCredential)) {
        throw new InvalidCredentialException(getName(), "Credential type not supported.");
    }

    XenonProperties xp = new XenonProperties(VALID_PROPERTIES, properties);

    long bufferSize = xp.getSizeProperty(BUFFER_SIZE);

    if (bufferSize <= 0 || bufferSize >= Integer.MAX_VALUE) {
        throw new InvalidPropertyException(ADAPTOR_NAME,
                "Invalid value for " + BUFFER_SIZE + ": " + bufferSize + " (must be between 1 and " + Integer.MAX_VALUE + ")");
    }

    FTPClient ftpClient = connect(location, credential);

    String cwd = null;

    try {
        cwd = getCurrentWorkingDirectory(ftpClient, location);
    } catch (Exception e) {
        try {
            ftpClient.disconnect();
        } catch (Exception ex) {
            // ignored
        }
        throw e;
    }

    LOGGER.debug("CWD is {}", cwd);

    return new FtpFileSystem(getNewUniqueID(), ADAPTOR_NAME, location, new Path(cwd), (int) bufferSize, ftpClient, credential, this, xp);
}
 
Example 18
Source File: FTPServerTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Test of obscure path names in the FTP server
 * 
 * RFC959 states that paths are constructed thus...
 * <string> ::= <char> | <char><string>
 * <pathname> ::= <string>
 * <char> ::= any of the 128 ASCII characters except <CR> and <LF>
 *       
 *  So we need to check how high characters and problematic are encoded     
 */
public void testPathNames() throws Exception
{
    
    logger.debug("Start testPathNames");
    
    FTPClient ftp = connectClient();

    String PATH1="testPathNames";
    
    try
    {
        int reply = ftp.getReplyCode();

        if (!FTPReply.isPositiveCompletion(reply))
        {
            fail("FTP server refused connection.");
        }
    
        boolean login = ftp.login(USER_ADMIN, PASSWORD_ADMIN);
        assertTrue("admin login successful", login);
                      
        reply = ftp.cwd("/Alfresco/User*Homes");
        assertTrue(FTPReply.isPositiveCompletion(reply));
                    
        // Delete the root directory in case it was left over from a previous test run
        try
        {
            ftp.removeDirectory(PATH1);
        }
        catch (IOException e)
        {
            // ignore this error
        }
        
        // make root directory for this test
        boolean success = ftp.makeDirectory(PATH1);
        assertTrue("unable to make directory:" + PATH1, success);
        
        success = ftp.changeWorkingDirectory(PATH1);
        assertTrue("unable to change to working directory:" + PATH1, success);
        
        assertTrue("with a space", ftp.makeDirectory("test space"));
        assertTrue("with exclamation", ftp.makeDirectory("space!"));
        assertTrue("with dollar", ftp.makeDirectory("space$"));
        assertTrue("with brackets", ftp.makeDirectory("space()"));
        assertTrue("with hash curley  brackets", ftp.makeDirectory("space{}"));


        //Pound sign U+00A3
        //Yen Sign U+00A5
        //Capital Omega U+03A9

        assertTrue("with pound sign", ftp.makeDirectory("pound \u00A3.world"));
        assertTrue("with yen sign", ftp.makeDirectory("yen \u00A5.world"));
        
        // Test steps that do not work
        // assertTrue("with omega", ftp.makeDirectory("omega \u03A9.world"));
        // assertTrue("with obscure ASCII chars", ftp.makeDirectory("?/.,<>"));    
    } 
    finally
    {
        // clean up tree if left over from previous run

        ftp.disconnect();
    }    


}
 
Example 19
Source File: FTPServerTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Create a user other than "admin" who has access to a set of files. 
 * 
 * Create a folder containing test.docx as user one
 * Update that file as user two.
 * Check user one can see user two's changes.
 * 
 * @throws Exception
 */
public void testTwoUserUpdate() throws Exception
{
    logger.debug("Start testFTPConnect");
    
    final String TEST_DIR="/Alfresco/User Homes/" + USER_ONE;
 
    FTPClient ftpOne = connectClient();
    FTPClient ftpTwo = connectClient();
    try
    {
        int reply = ftpOne.getReplyCode();

        if (!FTPReply.isPositiveCompletion(reply))
        {
            fail("FTP server refused connection.");
        }
        
        reply = ftpTwo.getReplyCode();

        if (!FTPReply.isPositiveCompletion(reply))
        {
            fail("FTP server refused connection.");
        }
    
        boolean login = ftpOne.login(USER_ONE, PASSWORD_ONE);
        assertTrue("user one login not successful", login);
        
        login = ftpTwo.login(USER_TWO, PASSWORD_TWO);
        assertTrue("user two login not successful", login);
        
        boolean success = ftpOne.changeWorkingDirectory("Alfresco");
        assertTrue("user one unable to cd to Alfreco", success);
        success = ftpOne.changeWorkingDirectory("User*Homes");
        assertTrue("user one unable to cd to User*Homes", success);
        success = ftpOne.changeWorkingDirectory(USER_ONE);
        assertTrue("user one unable to cd to " + USER_ONE, success);
        
        success = ftpTwo.changeWorkingDirectory("Alfresco");
        assertTrue("user two unable to cd to Alfreco", success);
        success = ftpTwo.changeWorkingDirectory("User*Homes");
        assertTrue("user two unable to cd to User*Homes", success);
        success = ftpTwo.changeWorkingDirectory(USER_ONE);
        assertTrue("user two unable to cd " + USER_ONE, success);

        // Create a file as user one
        String FILE1_CONTENT_1="test file 1 content";
        String FILE1_NAME = "test.docx";
        success = ftpOne.appendFile(FILE1_NAME , new ByteArrayInputStream(FILE1_CONTENT_1.getBytes("UTF-8")));
        assertTrue("user one unable to append file", success);
        
        // Update the file as user two
        String FILE1_CONTENT_2="test file content updated";
        success = ftpTwo.storeFile(FILE1_NAME , new ByteArrayInputStream(FILE1_CONTENT_2.getBytes("UTF-8")));
        assertTrue("user two unable to append file", success);
        
        // User one should read user2's content
        InputStream is1 = ftpOne.retrieveFileStream(FILE1_NAME);
        assertNotNull("is1 is null", is1);
        String content1 = inputStreamToString(is1);
        assertEquals("Content is not as expected", FILE1_CONTENT_2, content1);
        ftpOne.completePendingCommand();
        
        // User two should read user2's content
        InputStream is2 = ftpTwo.retrieveFileStream(FILE1_NAME);
        assertNotNull("is2 is null", is2);
        String content2 = inputStreamToString(is2);
        assertEquals("Content is not as expected", FILE1_CONTENT_2, content2);
        ftpTwo.completePendingCommand();
        logger.debug("Test finished");
  
    } 
    finally
    {
        ftpOne.dele(TEST_DIR);
        if(ftpOne != null)
        {
            ftpOne.disconnect();
        }
        if(ftpTwo != null)
        {
            ftpTwo.disconnect();
        }
    }       

}
 
Example 20
Source File: RinexNavigation.java    From GNSS_Compare with Apache License 2.0 4 votes vote down vote up
private RinexNavigationParserGps getFromFTP(String url) throws IOException{
	RinexNavigationParserGps rnp = null;

	String origurl = url;
	if(negativeChache.containsKey(url)){
		if(System.currentTimeMillis()-negativeChache.get(url).getTime() < 60*60*1000){
			throw new FileNotFoundException("cached answer");
		}else{
			negativeChache.remove(url);
		}
	}

	String filename = url.replaceAll("[ ,/:]", "_");
	if(filename.endsWith(".Z")) filename = filename.substring(0, filename.length()-2);
	File rnf = new File(RNP_CACHE,filename);

	if(rnf.exists()){
     System.out.println(url+" from cache file "+rnf);
     rnp = new RinexNavigationParserGps(rnf);
     try{
       rnp.init();
       return rnp;
     }
     catch( Exception e ){
       rnf.delete();
     }
	}
	
	// if the file doesn't exist of is invalid
	System.out.println(url+" from the net.");
	FTPClient ftp = new FTPClient();

	try {
		int reply;
		System.out.println("URL: "+url);
		url = url.substring("ftp://".length());
		String server = url.substring(0, url.indexOf('/'));
		String remoteFile = url.substring(url.indexOf('/'));
		String remotePath = remoteFile.substring(0,remoteFile.lastIndexOf('/'));
		remoteFile = remoteFile.substring(remoteFile.lastIndexOf('/')+1);

		ftp.connect(server);
		ftp.login("anonymous", "[email protected]");

		System.out.print(ftp.getReplyString());

		// After connection attempt, you should check the reply code to
		// verify
		// success.
		reply = ftp.getReplyCode();

		if (!FTPReply.isPositiveCompletion(reply)) {
			ftp.disconnect();
			System.err.println("FTP server refused connection.");
			return null;
		}

		ftp.enterLocalPassiveMode();
		ftp.setRemoteVerificationEnabled(false);

		System.out.println("cwd to "+remotePath+" "+ftp.changeWorkingDirectory(remotePath));
		System.out.println(ftp.getReplyString());
		ftp.setFileType(FTP.BINARY_FILE_TYPE);
		System.out.println(ftp.getReplyString());

		System.out.println("open "+remoteFile);
		InputStream is = ftp.retrieveFileStream(remoteFile);
		System.out.println(ftp.getReplyString());
		if(ftp.getReplyString().startsWith("550")){
			negativeChache.put(origurl, new Date());
			throw new FileNotFoundException();
		}
     InputStream uis = is;

		if(remoteFile.endsWith(".Z")){
			uis = new UncompressInputStream(is);
		}

		rnp = new RinexNavigationParserGps(uis,rnf);
		rnp.init();
		is.close();


		ftp.completePendingCommand();

		ftp.logout();
	} 
	finally {
		if (ftp.isConnected()) {
			try {
				ftp.disconnect();
			} catch (IOException ioe) {
				// do nothing
			}
		}
	}
	return rnp;
}