public static boolean fileExists(RemoteFileTemplate<LsEntry> template, final String... fileNames) { if (template != null) { return template.execute(session -> { ChannelSftp channel = (ChannelSftp) session.getClientInstance(); for (int i = 0; i < fileNames.length; i++) { try { SftpATTRS stat = channel.stat("si.sftp.sample/" + fileNames[i]); if (stat == null) { System.out.println("stat returned null for " + fileNames[i]); return false; } } catch (SftpException e) { System.out.println("Remote file not present: " + e.getMessage() + ": " + fileNames[i]); return false; } } return true; }); } else { return false; } }
protected <T> T doExecuteWithClient(final ClientCallback<FTPClient, T> callback) { return execute(session -> callback.doWithClient((FTPClient) session.getClientInstance())); }
protected <T> T doExecuteWithClient(final ClientCallback<ChannelSftp, T> callback) { return execute(session -> callback.doWithClient((ChannelSftp) session.getClientInstance())); }
private <V> V doInWorkingDirectory(Message<?> message, Session<FTPFile> session, Callable<V> task) throws IOException { Expression workDirExpression = this.workingDirExpression; FTPClient ftpClient = (FTPClient) session.getClientInstance(); String currentWorkingDirectory = null; boolean restoreWorkingDirectory = false;
@Test @SuppressWarnings("unchecked") public void testMGETOnNullDir() throws IOException { Session<FTPFile> session = ftpSessionFactory.getSession(); ((FTPClient) session.getClientInstance()).changeWorkingDirectory("ftpSource"); session.close(); this.inboundMGet.send(new GenericMessage<Object>("")); Message<?> result = this.output.receive(1000); assertNotNull(result); List<File> localFiles = (List<File>) result.getPayload(); assertThat(localFiles.size(), Matchers.greaterThan(0)); for (File file : localFiles) { assertThat(file.getName(), isOneOf(" localTarget1.txt", "localTarget2.txt")); assertThat(file.getName(), not(containsString("null"))); } }
@Test public void testInboundChannelAdapterWithNullDir() throws IOException { Session<FTPFile> session = ftpSessionFactory.getSession(); ((FTPClient) session.getClientInstance()).changeWorkingDirectory("ftpSource"); session.close(); this.ftpInbound.start(); Message<?> message = this.output.receive(10000); assertNotNull(message); assertThat(message.getPayload(), instanceOf(File.class)); assertEquals(" ftpSource1.txt", ((File) message.getPayload()).getName()); message = this.output.receive(10000); assertNotNull(message); assertThat(message.getPayload(), instanceOf(File.class)); assertEquals("ftpSource2.txt", ((File) message.getPayload()).getName()); assertNull(this.output.receive(10)); this.ftpInbound.stop(); }
@Test @SuppressWarnings("unchecked") public void testLsForNullDir() throws IOException { Session<FTPFile> session = ftpSessionFactory.getSession(); ((FTPClient) session.getClientInstance()).changeWorkingDirectory("ftpSource"); session.close(); this.inboundLs.send(new GenericMessage<String>("foo")); Message<?> receive = this.output.receive(10000); assertNotNull(receive); assertThat(receive.getPayload(), instanceOf(List.class)); List<String> files = (List<String>) receive.getPayload(); assertEquals(2, files.size()); assertThat(files, containsInAnyOrder(" ftpSource1.txt", "ftpSource2.txt")); FTPFile[] ftpFiles = ftpSessionFactory.getSession().list(null); for (FTPFile ftpFile : ftpFiles) { if (!ftpFile.isDirectory()) { assertTrue(files.contains(ftpFile.getName())); } } }
@SuppressWarnings("unchecked") @Override public <T, C> T executeWithClient(final ClientCallback<C, T> callback) { return callback.doWithClient((C) this.sessionFactory.getSession().getClientInstance()); }
@SuppressWarnings("unchecked") @Override public <T, C> T executeWithClient(final ClientCallback<C, T> callback) { return callback.doWithClient((C) this.sessionFactory.getSession().getClientInstance()); }
@Override @SuppressWarnings("unchecked") public <T, C> T executeWithClient(ClientCallback<C, T> callback) { return callback.doWithClient((C) this.sessionFactory.getSession().getClientInstance()); } }
@Override @SuppressWarnings("unchecked") public <T, C> T executeWithClient(ClientCallback<C, T> callback) { return callback.doWithClient((C) this.sessionFactory.getSession().getClientInstance()); } }
protected <T> T doExecuteWithClient(final ClientCallback<ChannelSftp, T> callback) { return execute(session -> callback.doWithClient((ChannelSftp) session.getClientInstance())); }
protected <T> T doExecuteWithClient(final ClientCallback<FTPClient, T> callback) { return execute(session -> callback.doWithClient((FTPClient) session.getClientInstance())); }
private <V> V doInWorkingDirectory(Message<?> message, Session<FTPFile> session, Callable<V> task) throws IOException { Expression workDirExpression = this.workingDirExpression; FTPClient ftpClient = (FTPClient) session.getClientInstance(); String currentWorkingDirectory = null; boolean restoreWorkingDirectory = false;