agave-systems/systems-core/src/main/java/org/iplantc/service/transfer/ftp/FTP2.java
/**
	 * Performs a directory listing using the mlsd command.
	 * This is the default approach when the feature is supported.
	 * 
	 * @param resolvedPath absolute path to file or folder on the system
	 * @return
	 * @throws IOException
	 * @throws RemoteDataException
	 */
Performs a directory listing using the mlsd command.
This is the default approach when the feature is supported.

@param resolvedPath absolute path to file or folder on the system
@return
@throws IOException
@throws RemoteDataException
Performs a directory listing using the mlsd command . This is the default approach when the feature is supported . @param resolvedPath absolute path to file or folder on the system @return @throws IOException @throws RemoteDataException
private List<RemoteFileInfo> doLs(String resolvedPath) 
	throws IOException, RemoteDataException
	{	
		final List<RemoteFileInfo> v = new ArrayList<RemoteFileInfo>();
		ByteArrayDataSink iSink = new ByteArrayDataSink();
		BufferedReader reader = null;
		try
		{
			if (!super.exists(resolvedPath)) {
				throw new FileNotFoundException("No such file or directory");
			}
			localServer.setProtectionBufferSize(Session.SERVER_DEFAULT);
			setType(Session.TYPE_ASCII);
			setMode(Session.MODE_STREAM);
			try 
			{
				setDTP(false);
				super.mlsd(resolvedPath, iSink);
			} 
			catch (ServerException e) 
			{
			    if (e.getMessage().contains("425 No data connection")) {
			        throw new RemoteConnectionException("Connection closed by server during listing. Resetting transfer.", e);
                }
			    else if (e.getMessage().contains("451 active connection failed")) {
					setDTP(true);
					super.mlsd(resolvedPath, iSink);
				} 
				else if (e.getMessage().toLowerCase().contains("illegal port command")) {
					this.bPassive = true;
					setDTP(true);
					return doLegacyLs(resolvedPath);
				} 
				else if (e.toString().contains("No such file or directory")) {
					throw new FileNotFoundException("No such file or directory");
				} else if (e.toString().contains("Permission denied")) {
					throw new RemoteDataException("Permission denied", e);
				} else {
				    throw new RemoteDataException("Failed to list path " + resolvedPath.replace(homeDir,  ""), e);
				}
			}
			reader = new BufferedReader(new StringReader(iSink.getData().toString()));
	        MlsxEntry entry = null;
	        String line = null;
	        long entriesReturned = 0;
	        while ((line = reader.readLine()) != null) 
	        {
	            try {
	                entry = new MlsxEntry(line);
	            } catch (FTPException e) {
	                ClientException ce = new ClientException(
	                    		ClientException.UNSPECIFIED, 
	                    		"Could not create MlsxEntry");
	                ce.setRootCause(e);
	                throw ce;
	            }
	            if (!entry.getFileName().equals(".") && !entry.getFileName().equals("..")) 
	            {
	                RemoteFileInfo childInfo = new RemoteFileInfo(entry);
	                fileInfoCache.put(resolvedPath + "/" + childInfo.getName(), childInfo);
	                v.add(childInfo);
	            }
	            entriesReturned++;
	        }
	        if (entriesReturned == 0) {
	        	throw new RemoteDataException("Permission denied"); 
	        }
			return v;
		}
		catch (IOException e) {
			throw e;
		}
		catch (RemoteDataException e) {
			throw e;
		}
		catch (Exception e) {
			throw new RemoteDataException("Failed to obtain directory listing from remote system.", e);
		} 
		finally {
			try { reader.close(); } catch (Exception e) {}
		}
	}
private List < RemoteFileInfo > doLs ( String resolvedPath ) throws IOException , RemoteDataException { final List < RemoteFileInfo > v = new ArrayList < RemoteFileInfo > ( ) ; ByteArrayDataSink iSink = new ByteArrayDataSink ( ) ; BufferedReader reader = null ; try { if ( ! super . exists ( resolvedPath ) ) { throw new FileNotFoundException ( "No such file or directory" ) ; } localServer . setProtectionBufferSize ( Session . SERVER_DEFAULT ) ; setType ( Session . TYPE_ASCII ) ; setMode ( Session . MODE_STREAM ) ; try { setDTP ( false ) ; super . mlsd ( resolvedPath , iSink ) ; } catch ( ServerException e ) { if ( e . getMessage ( ) . contains ( "425 No data connection" ) ) { throw new RemoteConnectionException ( "Connection closed by server during listing. Resetting transfer." , e ) ; } else if ( e . getMessage ( ) . contains ( "451 active connection failed" ) ) { setDTP ( true ) ; super . mlsd ( resolvedPath , iSink ) ; } else if ( e . getMessage ( ) . toLowerCase ( ) . contains ( "illegal port command" ) ) { this . bPassive = true ; setDTP ( true ) ; return doLegacyLs ( resolvedPath ) ; } else if ( e . toString ( ) . contains ( "No such file or directory" ) ) { throw new FileNotFoundException ( "No such file or directory" ) ; } else if ( e . toString ( ) . contains ( "Permission denied" ) ) { throw new RemoteDataException ( "Permission denied" , e ) ; } else { throw new RemoteDataException ( "Failed to list path " + resolvedPath . replace ( homeDir , "" ) , e ) ; } } reader = new BufferedReader ( new StringReader ( iSink . getData ( ) . toString ( ) ) ) ; MlsxEntry entry = null ; String line = null ; long entriesReturned = 0 ; while ( ( line = reader . readLine ( ) ) != null ) { try { entry = new MlsxEntry ( line ) ; } catch ( FTPException e ) { ClientException ce = new ClientException ( ClientException . UNSPECIFIED , "Could not create MlsxEntry" ) ; ce . setRootCause ( e ) ; throw ce ; } if ( ! entry . getFileName ( ) . equals ( "." ) && ! entry . getFileName ( ) . equals ( ".." ) ) { RemoteFileInfo childInfo = new RemoteFileInfo ( entry ) ; fileInfoCache . put ( resolvedPath + "/" + childInfo . getName ( ) , childInfo ) ; v . add ( childInfo ) ; } entriesReturned ++ ; } if ( entriesReturned == 0 ) { throw new RemoteDataException ( "Permission denied" ) ; } return v ; } catch ( IOException e ) { throw e ; } catch ( RemoteDataException e ) { throw e ; } catch ( Exception e ) { throw new RemoteDataException ( "Failed to obtain directory listing from remote system." , e ) ; } finally { try { reader . close ( ) ; } catch ( Exception e ) { } } }
Performs a directory listing using the mlsd command.
Performs a directory listing using the mlsd command .
// try adding mlsd support here. Will give info on files not staged from tape yet // the ls command will not always throw a proper 404 exception,  // so we do a check her to catch those exceptions before making // the actual ls call. //Transfer type must be ASCII //				setPassive(); //				setLocalActive(); //				setProtectionBufferSize(16384) // try to reverse the mode and see if that helps //					setLocalPassive(); //					setActive(); // try to reverse the mode and see if that helps //					setLocalPassive(); //					setActive();