Search in sources :

Example 11 with LsEntry

use of com.jcraft.jsch.ChannelSftp.LsEntry in project opennms by OpenNMS.

the class Sftp3gppUrlConnection method getFileList.

/**
     * Gets the file list (from the path defined on the URL).
     *
     * @return the file list
     * @throws SftpException the SFTP exception
     * @throws IOException Signals that an I/O exception has occurred.
     */
@SuppressWarnings("unchecked")
public List<String> getFileList() throws SftpException, IOException {
    List<String> files = new ArrayList<String>();
    Vector<LsEntry> entries = getChannel().ls(url.getPath());
    for (LsEntry entry : entries) {
        if (entry.getFilename().startsWith("."))
            continue;
        files.add(entry.getFilename());
    }
    Collections.sort(files);
    return files;
}
Also used : ArrayList(java.util.ArrayList) LsEntry(com.jcraft.jsch.ChannelSftp.LsEntry)

Example 12 with LsEntry

use of com.jcraft.jsch.ChannelSftp.LsEntry in project bamboobsc by billchen198318.

the class SFtpClientUtils method getRemoteFileList.

@SuppressWarnings("unchecked")
public static Vector<LsEntry> getRemoteFileList(String user, String password, String addr, int port, String cwd) throws JSchException, SftpException, Exception {
    Session session = getSession(user, password, addr, port);
    Vector<LsEntry> lsVec = null;
    Channel channel = session.openChannel("sftp");
    channel.connect();
    ChannelSftp sftpChannel = (ChannelSftp) channel;
    try {
        //sftpChannel.lpwd()
        lsVec = (Vector<LsEntry>) sftpChannel.ls(cwd);
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    } finally {
        sftpChannel.exit();
        channel.disconnect();
        session.disconnect();
    }
    return lsVec;
}
Also used : ChannelSftp(com.jcraft.jsch.ChannelSftp) Channel(com.jcraft.jsch.Channel) LsEntry(com.jcraft.jsch.ChannelSftp.LsEntry) SftpException(com.jcraft.jsch.SftpException) JSchException(com.jcraft.jsch.JSchException) Session(com.jcraft.jsch.Session)

Aggregations

LsEntry (com.jcraft.jsch.ChannelSftp.LsEntry)12 SftpException (com.jcraft.jsch.SftpException)8 ArrayList (java.util.ArrayList)7 IOException (java.io.IOException)4 FileStatus (org.apache.hadoop.fs.FileStatus)4 Path (org.apache.hadoop.fs.Path)4 JschSftpClientException (com.axway.ats.core.ssh.exceptions.JschSftpClientException)2 ChannelSftp (com.jcraft.jsch.ChannelSftp)2 FileNotFoundException (java.io.FileNotFoundException)2 Vector (java.util.Vector)2 Matcher (java.util.regex.Matcher)2 Channel (com.jcraft.jsch.Channel)1 LsEntrySelector (com.jcraft.jsch.ChannelSftp.LsEntrySelector)1 JSchException (com.jcraft.jsch.JSchException)1 Session (com.jcraft.jsch.Session)1 SftpATTRS (com.jcraft.jsch.SftpATTRS)1 File (java.io.File)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1