@Test(groups = "spring") public void testDelete() throws SftpException { final Iterable<?> iterable = sftpChannel.ls("."); for (Object object : iterable) { com.jcraft.jsch.ChannelSftp.LsEntry entry = (LsEntry) object; System.out.println(entry.getFilename()); } // assert sftpChannel.lstat("to_delete") == null; sftpChannel.put(new ByteArrayInputStream("Hello World!".getBytes()), "to_delete"); assert sftpChannel.lstat("to_delete") != null; sftpChannel.rm("to_delete"); // Will throw exception if fails }
private void setLastModified(File localFile) throws JSchException { SftpATTRS fileAttributes = null; String remotePath = null; ChannelSftp channel = openSftpChannel(); channel.connect(); try { fileAttributes = channel.lstat(remoteDir(remoteFile) + localFile.getName()); } catch (SftpException e) { throw new JSchException("failed to stat remote file", e); } FileUtils.getFileUtils() .setFileLastModified(localFile, ((long) fileAttributes.getMTime()) * 1000); }
@Test(groups = "spring") public void testCanMoveObjectsInFolders() throws SftpException { sftpChannel.rename(TestDataCreator.TO_MOVE_FILE_NAME, "toloc"); sftpChannel.lstat("toloc"); }