List of usage examples for org.apache.commons.net.ftp FTPSClient listFiles
public FTPFile[] listFiles(String pathname) throws IOException
From source file:org.mule.transport.ftps.FtpsConnector.java
/** * Creates a new FTPSClient that logs in and changes the working directory using the data * provided in <code>endpoint</code>. *///w ww .ja v a2 s .c o m protected FTPSClient createFTPSClient(ImmutableEndpoint endpoint) throws Exception { EndpointURI uri = endpoint.getEndpointURI(); FTPSClient client = this.getFtp(uri); client.setDataTimeout(endpoint.getResponseTimeout()); this.enterActiveOrPassiveMode(client, endpoint); this.setupFileType(client, endpoint); String path = uri.getPath(); // only change directory if one was configured if (StringUtils.isNotBlank(path)) { // MULE-2400: if the path begins with '~' we must strip the first '/' to make things // work with FTPSClient if ((path.length() >= 2) && (path.charAt(1) == '~')) { path = path.substring(1); } //Checking if it is a file or a directory boolean isFile = this.isFile(endpoint, client); if (!isFile && !client.changeWorkingDirectory(path)) { throw new IOException(MessageFormat.format( "Failed to change working directory to {0}. Ftp error: {1}", path, client.getReplyCode())); } else if (isFile) { // Changing the working directory to the parent folder, it should be better if // the FTPSClient API would provide a way to retrieve the parent folder FTPFile[] listFiles = client.listFiles(path); String directory = path.replaceAll(listFiles[0].getName(), ""); client.changeWorkingDirectory(directory); } } return client; }
From source file:org.mule.transport.ftps.FtpsConnector.java
protected boolean isFile(ImmutableEndpoint endpoint, FTPSClient client) throws IOException { //Checking if it is a file or a directory String path = endpoint.getEndpointURI().getPath(); FTPFile[] listFiles = client.listFiles(path); return listFiles.length == 1 && listFiles[0].isFile(); }
From source file:org.mule.transport.ftps.FtpsMessageRequester.java
/** * Make a specific request to the underlying transport * * @param timeout The maximum time the operation should block before returning. * The call should return immediately if there is data available. If * no data becomes available before the timeout elapses, null will be * returned.//from w w w . java 2s .c om * @return The result of the request wrapped in a MuleMessage object. <code>null</code> will be * returned if no data was avaialable * @throws Exception if the call to the underlying protocol cuases an exception */ @Override protected MuleMessage doRequest(long timeout) throws Exception { FTPSClient client = null; try { client = connector.createFTPSClient(endpoint); FTPFile fileToProcess; if (connector.isFile(endpoint, client)) { fileToProcess = client.listFiles(endpoint.getEndpointURI().getPath())[0]; if (!isValid(fileToProcess, getFilenameFilter())) { return null; } } else { fileToProcess = findFileToProcess(client); if (fileToProcess == null) { return null; } } fileToProcess = prepareFile(client, fileToProcess); FtpsMuleMessageFactory messageFactory = createMuleMessageFactory(client); MuleMessage message = messageFactory.create(fileToProcess, endpoint.getEncoding(), endpoint.getMuleContext()); postProcess(client, fileToProcess, message); return message; } finally { connector.releaseFtp(endpoint.getEndpointURI(), client); } }