/** * copy a directory from the remote host to the local one. * * @param sourceLocation the source directory on the remote host * @param targetLocation the target directory on the local host * @param sftpClient is an instance of SFTPv3Client that makes SFTP client connection over SSH-2 * @return the number of files successfully copied * @throws Exception */ @SuppressWarnings("unchecked") private void GetFiles( String sourceLocation, String targetLocation, SFTPv3Client sftpClient, Pattern pattern, Job parentJob) throws Exception { String sourceFolder = "."; if (!Const.isEmpty(sourceLocation)) { sourceFolder = sourceLocation + FTPUtils.FILE_SEPARATOR; } else { sourceFolder += FTPUtils.FILE_SEPARATOR; } Vector<SFTPv3DirectoryEntry> filelist = sftpClient.ls(sourceFolder); if (filelist != null) { Iterator<SFTPv3DirectoryEntry> iterator = filelist.iterator(); while (iterator.hasNext() && !parentJob.isStopped()) { SFTPv3DirectoryEntry dirEntry = iterator.next(); if (dirEntry == null) { continue; } if (dirEntry.filename.equals(".") || dirEntry.filename.equals("..") || isDirectory(sftpClient, sourceFolder + dirEntry.filename)) { continue; } if (getFileWildcard(dirEntry.filename, pattern)) { // Copy file from remote host copyFile( sourceFolder + dirEntry.filename, targetLocation + FTPUtils.FILE_SEPARATOR + dirEntry.filename, sftpClient); } } } }