Logo Search packages:      
Sourcecode: jftp version File versions  Download package

String [] net::sf::jftp::net::FtpConnection::sortLs (  )  [inline]

Sort the filenames of the current working dir an return an array.

The Array should be in sync with the other sort*-Methods

Returns:
An String-array of sizes containing the name of the file (symlinks are resolved)

Implements net::sf::jftp::net::BasicConnection.

Definition at line 626 of file FtpConnection.java.

References dateVector, getOsType(), giveFile(), and parseSymlink().

Referenced by cleanDir(), exists(), and rawUpload().

    {
        try
        {
            boolean newUnixDateStyle = false;
            dateVector = new Vector();
            currentFiles.removeAllElements();
            
            for(int i=0; i<currentListing.size(); i++)
            {
                String tmp = (String) currentListing.get(i);

                // ------------------- VMS override --------------------
                if(getOsType().indexOf("VMS") >= 0)
                {
                    int x = tmp.indexOf(";");

                    if(x < 0)
                    {
                        continue;
                    }

                    tmp = tmp.substring(0, x);

                    if(tmp.endsWith("DIR"))
                    {
                        currentFiles.add(tmp.substring(0, tmp.lastIndexOf(".")) +
                                    "/");
                    }
                    else
                    {
                        currentFiles.add(tmp);
                    }

                    //Log.out("listing - (vms parser): " + tmp);

                    continue;
                }
                else if(getOsType().indexOf("OS/2") >= 0)
                {
                    StringTokenizer to2 = new StringTokenizer(tmp, " ", true);

                    if(giveFile(to2, 2).indexOf("DIR") >= 0)
                    {
                        to2 = new StringTokenizer(tmp, " ", true);
                        tmp = giveFile(to2, 5);
                        tmp = tmp + "/";
                    }
                    else
                    {
                        to2 = new StringTokenizer(tmp, " ", true);

                        if(giveFile(to2, 1).indexOf("DIR") >= 0)
                        {
                            //Log.out("OS/2 parser (DIRFIX): " + tmp);
                            to2 = new StringTokenizer(tmp, " ", true);
                            tmp = giveFile(to2, 4);
                            tmp = tmp + "/";
                        }
                        else
                        {
                            to2 = new StringTokenizer(tmp, " ", true);
                            tmp = giveFile(to2, 4);
                        }
                    }

                    Log.out("OS/2 parser: " + tmp);
                    currentFiles.add(tmp);

                    continue;
                }

                // -------------------------------------------------------
                // ------------------- MVS override --------------------
                if(getOsType().indexOf("MVS") >= 0)
                {
                    if(tmp.startsWith("Volume") || (tmp.indexOf(" ") < 0))
                    {
                        Log.out("->" + tmp);

                        continue;
                    }

                    String f = tmp.substring(tmp.lastIndexOf(" ")).trim();
                    String isDir = tmp.substring(tmp.lastIndexOf(" ") - 5,
                                                 tmp.lastIndexOf(" "));

                    if(isDir.indexOf("PO") >= 0)
                    {
                        currentFiles.add(f + "/");
                    }
                    else
                    {
                        currentFiles.add(f);
                    }

                    Log.out("listing - (mvs parser): " + tmp + " -> " + f);
                    continue;
                }
                else if(getOsType().indexOf("OS/2") >= 0)
                {
                    StringTokenizer to2 = new StringTokenizer(tmp, " ", true);

                    if(giveFile(to2, 2).indexOf("DIR") >= 0)
                    {
                        to2 = new StringTokenizer(tmp, " ", true);
                        tmp = giveFile(to2, 5);
                        tmp = tmp + "/";
                    }
                    else
                    {
                        to2 = new StringTokenizer(tmp, " ", true);

                        if(giveFile(to2, 1).indexOf("DIR") >= 0)
                        {
                            //Log.out("OS/2 parser (DIRFIX): " + tmp);
                            to2 = new StringTokenizer(tmp, " ", true);
                            tmp = giveFile(to2, 4);
                            tmp = tmp + "/";
                        }
                        else
                        {
                            to2 = new StringTokenizer(tmp, " ", true);
                            tmp = giveFile(to2, 4);
                        }
                    }

                    Log.out("OS/2 parser: " + tmp);
                    currentFiles.add(tmp);

                    continue;
                }

                // -------------------------------------------------------
                // ------------------- Unix, Windows and others -----
                boolean isDir = false;
                boolean isLink = false;

                if(tmp.startsWith("d") || (tmp.indexOf("<DIR>") >= 0))
                {
                    isDir = true;
                }

                if(tmp.startsWith("l"))
                {
                    isLink = true;
                }

                if(tmp.startsWith("/") && (tmp.indexOf("denied") > 0))
                {
                    continue;
                }

                StringTokenizer to = new StringTokenizer(tmp, " ", false);
                StringTokenizer to2 = new StringTokenizer(tmp, " ", true);

                int tokens = to.countTokens();

                //Log.out("listing: tokens: " + tokens + " - " + tmp);
                boolean set = false;

                //-----preparsing-----
                int lcount = 0;

                if(!newUnixDateStyle)
                {
                    try
                    {
                        StringTokenizer tx = new StringTokenizer(tmp, " ", false);
                        tx.nextToken();
                        tx.nextToken();
                        tx.nextToken();
                        tx.nextToken();
                        tx.nextToken();

                        String date = tx.nextToken();
                        int x = date.indexOf("-");
                        int y = date.lastIndexOf("-");

                        if(y > x)
                        {
                            Log.debug("Using new Unix date parser");
                            newUnixDateStyle = true;
                        }
                    }
                    catch(Exception ex)
                    {
                        Log.out("could not preparse line: " + tmp);
                        lcount++;

                        //ex.printStackTrace();
                    }
                }

                //--------------------
                //Log.out("tmp: " + tmp);
                if(newUnixDateStyle) // unix, too
                {
                    set = true;

                    //Log.out("listing - (unix parser #2, token 7): " + tmp);
                    //------- date parser testing ---------
                    try
                    {
                        //Log.out(">>> date parser: " + tmp);
                        StringTokenizer to3 = new StringTokenizer(tmp, " ", true);
                        String date = giveFile(to3, 5);
                        String date2 = date.substring(date.indexOf("-") + 1);
                        date2 = date2.substring(date.indexOf("-") + 2);

                        //Log.out("date1: "+date+"/"+"date2: "+date2);  
                        String t = date;
                        String y = t.substring(0, t.indexOf("-"));
                        String m = t.substring(t.indexOf("-") + 1,
                                               t.indexOf("-") + 3);
                        String m1 = t.substring(t.indexOf("-") + 1);
                        String day = m1.substring(m1.indexOf("-") + 1,
                                                  m1.indexOf("-") + 3);
                        String h = date2.substring(0, date2.indexOf(":"));
                        String min = date2.substring(date2.indexOf(":") + 1,
                                                     date2.indexOf(":") + 3);

                        //Log.out("day:"+day+"year:"+y+"mon:"+m+"hour:"+h+"m:"+min);
                        Date d = new Date();
                        d.setDate(Integer.parseInt(day));
                        d.setYear(Integer.parseInt(y));
                        d.setMonth(Integer.parseInt(m) - 1);
                        d.setHours(Integer.parseInt(h));
                        d.setMinutes(Integer.parseInt(min));

                        dateVector.add(d);

                        //Log.out("+++ date: \"" + d.toString() + "\"");
                    }
                    catch(Exception ex)
                    {
                        ex.printStackTrace();

                        //set = false;
                    }

                    // -----------------------------
                    tmp = giveFile(to2, 7);

                    if(lcount > 1)
                    {
                        dateVector = new Vector();
                    }
                }
                else if(tokens > 8) // unix
                {
                    set = true;
                    tmp = giveFile(to2, 8);

                    //Log.out("listing - (unix parser, token 8): " + tmp);
                }
                else if(tokens > 3) // windows
                {
                    set = true;
                    tmp = giveFile(to2, 3);

                    if(tmp.startsWith("<error>"))
                    {
                        tmp = giveFile(to2, 4);

                        //Log.out("listing - (windows parser, token 4): " + tmp);
                    }
                    else
                    {
                        //Log.out("listing - (windows parser, token 3): " + tmp);
                    }
                }

                if(tmp.startsWith("<error>") || !set)
                {
                    if(tokens < 3)
                    {
                        continue;
                    }

                    tmp = giveFile(to2, tokens);
                    Log.out("listing - WARNING: listing style unknown, using last token as filename!");
                    Log.out("listing - this may work but may also fail, filesizes and permissions will probably fail, too...");
                    Log.out("listing - please send us a feature request with the serveraddress to let us support this listing style :)");
                    Log.out("listing - (backup parser, token " + tokens +
                            " ): " + tmp);
                }

                if(isDir)
                {
                    tmp = tmp + "/";
                }
                else if(isLink)
                {
                    tmp = tmp + "###";
                }

                currentFiles.add(tmp);
                // -------------------------------------------------------------
            }

            String[] files = toArray(currentFiles);

            for(int i = 0; i < files.length; i++)
            {
                files[i] = parseSymlink(files[i]);

                //System.out.println("> " + files[i]+":"+dateVector.elementAt(i));
                //System.out.println("> " + files.length+":"+dateVector.size());
            }

            return files;
        }
        catch(Exception ex)
        {
            Log.debug(ex.toString() + " @FtpConnection::sortLs");
            ex.printStackTrace();
        }

        //------- date parser test ------

        /*
        String[] x = (String[]) dateVector.toArray();
        for(int i=0; i<x.length; i++)
        {
                Log.out(":"+x[i]);
        }
        */

        //-------------------------------
        return new String[0];
    }


Generated by  Doxygen 1.6.0   Back to index