Project

General

Profile

Actions

Bug #4474

closed

SFTP dir listing non-deterministic behaviour

Added by Hajnal Akos almost 12 years ago. Updated over 11 years ago.

Status:
Closed
Priority:
Normal
Assigned To:
Category:
Non-grid adaptors
Target version:
Start date:
05/08/2013
Due date:
% Done:

0%

Estimated time:

Description

The code below throws various exceptions - differ from run to run. What is strange, changing the call createFile to the one with Flags.NONE works fine:

File f = FileFactory.createFile(session, URLFactory.createURL(dir.getURL().toString() + fileName), Flags.NONE.getValue());

Here is the original code:


import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import org.ogf.saga.context.Context;
import org.ogf.saga.context.ContextFactory;
import org.ogf.saga.file.File;
import org.ogf.saga.file.FileFactory;
import org.ogf.saga.namespace.NSDirectory;
import org.ogf.saga.namespace.NSFactory;
import org.ogf.saga.permissions.Permission;
import org.ogf.saga.session.Session;
import org.ogf.saga.session.SessionFactory;
import org.ogf.saga.url.URL;
import org.ogf.saga.url.URLFactory;

public class Ssh {

    public static void main(String[] args) throws Exception {
        URL url = URLFactory.createURL("sftp://192.168.154.102");
        Session session = SessionFactory.createSession(false);
        Context ctx = ContextFactory.createContext("UserPass");
        ctx.setAttribute(Context.USERID, "root");
        ctx.setAttribute(Context.USERPASS, "***");
        session.addContext(ctx);
        NSDirectory dir = NSFactory.createNSDirectory(session, url);
        List <URL> dirContent = dir.list();
        dir.close();

        for (URL dirEntry: dirContent) {
             if (dir.isEntry(dirEntry)) {
                 String fileName = dirEntry.getPath();
                 File f = FileFactory.createFile(session, URLFactory.createURL(dir.getURL().toString() + fileName));
                 long size = f.getSize();
                 long date = f.getMTime();
                 boolean readPermisssion = f.permissionsCheck("*", Permission.READ.getValue());
                 boolean writePermission = f.permissionsCheck("*", Permission.WRITE.getValue());
                 boolean executePermission = f.permissionsCheck("*", Permission.EXEC.getValue());
                 f.close();

                 System.out.println(
                         fileName + " " +
                         (readPermisssion ? "r" : "-") + (writePermission ? "w" : "-") + (executePermission ? "x" : "-") + " " + 
                         (date != 0l ? new SimpleDateFormat("dd-MMM-yyyy HH:mm").format(new Date(date)) : "?") + " " 
                         + (size != 0l ? "" + size + "B": "?")
                         );
             }
        }
    }
}

Stacktrace:

Exception in thread "main" NoSuccess: 4: 
    at fr.in2p3.jsaga.adaptor.ssh.data.SFTPDataAdaptor.getAttributes(SFTPDataAdaptor.java:119)
    at fr.in2p3.jsaga.impl.permissions.AbstractDataPermissionsImpl._getFileAttributes(AbstractDataPermissionsImpl.java:365)
    at fr.in2p3.jsaga.impl.file.AbstractSyncFileImpl.getSizeSync(AbstractSyncFileImpl.java:266)
    at fr.in2p3.jsaga.impl.file.FileImpl.getSize(FileImpl.java:48)
    at Ssh.main(Ssh.java:34)
Caused by: 4: 
    at com.jcraft.jsch.ChannelSftp._lstat(ChannelSftp.java:2001)
    at com.jcraft.jsch.ChannelSftp.lstat(ChannelSftp.java:1967)
    at fr.in2p3.jsaga.adaptor.ssh.data.SFTPDataAdaptor.getAttributes(SFTPDataAdaptor.java:112)
    ... 4 more
Caused by: java.lang.IndexOutOfBoundsException
    at java.io.PipedInputStream.read(PipedInputStream.java:355)
    at com.jcraft.jsch.ChannelSftp.fill(ChannelSftp.java:2527)
    at com.jcraft.jsch.ChannelSftp.fill(ChannelSftp.java:2519)
    at com.jcraft.jsch.ChannelSftp._lstat(ChannelSftp.java:1986)
    ... 6 more

The request is not in order.
Exception in thread "main" NoSuccess: 1: End of file
    at fr.in2p3.jsaga.adaptor.ssh.data.SFTPDataAdaptor.getAttributes(SFTPDataAdaptor.java:119)
    at fr.in2p3.jsaga.impl.permissions.AbstractDataPermissionsImpl._getFileAttributes(AbstractDataPermissionsImpl.java:365)
    at fr.in2p3.jsaga.impl.file.AbstractSyncFileImpl.getSizeSync(AbstractSyncFileImpl.java:266)
    at fr.in2p3.jsaga.impl.file.FileImpl.getSize(FileImpl.java:48)
    at Ssh.main(Ssh.java:34)
Caused by: 1: End of file
    at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2491)
    at com.jcraft.jsch.ChannelSftp._lstat(ChannelSftp.java:1991)
    at com.jcraft.jsch.ChannelSftp.lstat(ChannelSftp.java:1967)
    at fr.in2p3.jsaga.adaptor.ssh.data.SFTPDataAdaptor.getAttributes(SFTPDataAdaptor.java:112)
    ... 4 more
Exception in thread "main" NotImplemented: Not supported for this protocol: sftp
    at fr.in2p3.jsaga.impl.namespace.AbstractSyncNSEntryImpl.getMTimeSync(AbstractSyncNSEntryImpl.java:380)
    at fr.in2p3.jsaga.impl.namespace.AbstractNSEntryImpl.getMTime(AbstractNSEntryImpl.java:164)
    at fr.in2p3.jsaga.impl.file.AbstractNSEntryImplWithStream.getMTime(AbstractNSEntryImplWithStream.java:91)
    at Ssh.main(Ssh.java:35)
Exception in thread "main" NoSuccess: 4: 
    at fr.in2p3.jsaga.adaptor.ssh.data.SFTPDataAdaptor.getAttributes(SFTPDataAdaptor.java:119)
    at fr.in2p3.jsaga.impl.permissions.AbstractDataPermissionsImpl._getFileAttributes(AbstractDataPermissionsImpl.java:365)
    at fr.in2p3.jsaga.impl.file.AbstractSyncFileImpl.getSizeSync(AbstractSyncFileImpl.java:266)
    at fr.in2p3.jsaga.impl.file.FileImpl.getSize(FileImpl.java:48)
    at Ssh.main(Ssh.java:34)
Caused by: 4: 
    at com.jcraft.jsch.ChannelSftp._lstat(ChannelSftp.java:1993)
    at com.jcraft.jsch.ChannelSftp.lstat(ChannelSftp.java:1967)
    at fr.in2p3.jsaga.adaptor.ssh.data.SFTPDataAdaptor.getAttributes(SFTPDataAdaptor.java:112)
    ... 4 more
Actions #1

Updated by Schwarz Lionel over 11 years ago

  • Status changed from New to Closed
  • Assigned To set to Schwarz Lionel
  • Target version set to 1.0.0

The SSH adaptor has been refactored with a new library OrionII.

Actions

Also available in: Atom PDF