Examples of SmbFile


Examples of com.knowgate.jcifs.smb.SmbFile

        return f1.lastModified() > f2.lastModified() ? -1 : 1;
    }
    protected void doDirectory( HttpServletRequest req, HttpServletResponse resp, SmbFile dir ) throws IOException {
        PrintWriter out;
        SmbFile[] dirents;
        SmbFile f;
        int i, j, len, maxLen, dirCount, fileCount, sort;
        String str, name, path, fmt;
        LinkedList sorted;
        ListIterator iter;
        SimpleDateFormat sdf = new SimpleDateFormat( "MM/d/yy h:mm a" );
        GregorianCalendar cal = new GregorianCalendar();

        sdf.setCalendar( cal );

        dirents = dir.listFiles();
        sorted = new LinkedList();
        if(( fmt = req.getParameter( "fmt" )) == null ) {
            fmt = "col";
        }
        sort = 0;
        if(( str = req.getParameter( "sort" )) == null || str.equals( "name" )) {
            sort = 0;
        } else if( str.equals( "size" )) {
            sort = 1;
        } else if( str.equals( "type" )) {
            sort = 2;
        } else if( str.equals( "date" )) {
            sort = 3;
        }
        dirCount = fileCount = 0;
        maxLen = 28;
        for( i = 0; i < dirents.length; i++ ) {
            try {
                if( dirents[i].getType() == SmbFile.TYPE_NAMED_PIPE ) {
                    continue;
                }
            } catch( SmbAuthException sae ) {
            } catch( SmbException se ) {
                if( se.getNtStatus() != se.NT_STATUS_UNSUCCESSFUL ) {
                    throw se;
                }
            }
            if( dirents[i].isDirectory() ) {
                dirCount++;
            } else {
                fileCount++;
            }

            name = dirents[i].getName();
            len = name.length();
            if( len > maxLen ) {
                maxLen = len;
            }

            iter = sorted.listIterator();
            for( j = 0; iter.hasNext(); j++ ) {
                if( sort == 0 ) {
                    if( compareNames( dirents[i], name, (SmbFile)iter.next() ) < 0 ) {
                        break;
                    }
                } else if( sort == 1 ) {
                    if( compareSizes( dirents[i], name, (SmbFile)iter.next() ) < 0 ) {
                        break;
                    }
                } else if( sort == 2 ) {
                    if( compareTypes( dirents[i], name, (SmbFile)iter.next() ) < 0 ) {
                        break;
                    }
                } else if( sort == 3 ) {
                    if( compareDates( dirents[i], name, (SmbFile)iter.next() ) < 0 ) {
                        break;
                    }
                }
            }
            sorted.add( j, dirents[i] );
        }
        if( maxLen > 50 ) {
            maxLen = 50;
        }
        maxLen *= 9; /* convert to px */

        out = resp.getWriter();

        resp.setContentType( "text/html" );

        out.println( "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">" );
        out.println( "<html><head><title>Network Explorer</title>" );
        out.println( "<meta HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">" );
        out.println( "<style TYPE=\"text/css\">" );

        out.println( style );

        if( dirents.length < 200 ) {
            out.println( "    a:hover {" );
            out.println( "        background: #a2ff01;" );
            out.println( "    }" );
        }

        out.println( "</STYLE>" );
        out.println( "</head><body>" );

        out.print( "<a class=\"sort\" style=\"width: " + maxLen + ";\" href=\"?fmt=detail&sort=name\">Name</a>" );
        out.println( "<a class=\"sort\" href=\"?fmt=detail&sort=size\">Size</a>" );
        out.println( "<a class=\"sort\" href=\"?fmt=detail&sort=type\">Type</a>" );
        out.println( "<a class=\"sort\" style=\"width: 180\" href=\"?fmt=detail&sort=date\">Modified</a><br clear='all'><p>" );

        path = dir.getCanonicalPath();

        if( path.length() < 7 ) {
            out.println( "<b><big>smb://</big></b><br>" );
            path = ".";
        } else {
            out.println( "<b><big>" + path + "</big></b><br>" );
            path = "../";
        }
        out.println( (dirCount + fileCount) + " objects (" + dirCount + " directories, " + fileCount + " files)<br>" );
        out.println( "<b><a class=\"plain\" href=\".\">normal</a> | <a class=\"plain\" href=\"?fmt=detail\">detailed</a></b>" );
        out.println( "<p><table border='0' cellspacing='0' cellpadding='0'><tr><td>" );

        out.print( "<A style=\"width: " + maxLen );
        out.print( "; height: 18;\" HREF=\"" );
        out.print( path );
        out.println( "\"><b>&uarr;</b></a>" );
        if( fmt.equals( "detail" )) {
            out.println( "<br clear='all'>" );
        }

        if( path.length() == 1 || dir.getType() != SmbFile.TYPE_WORKGROUP ) {
            path = "";
        }

        iter = sorted.listIterator();
        while( iter.hasNext() ) {
            f = (SmbFile)iter.next();
            name = f.getName();

            if( fmt.equals( "detail" )) {
                out.print( "<A style=\"width: " + maxLen );
                out.print( "; height: 18;\" HREF=\"" );
                out.print( path );
                out.print( name );

                if( f.isDirectory() ) {
                    out.print( "?fmt=detail\"><b>" );
                    out.print( name );
                    out.print( "</b></a>" );
                } else {
                    out.print( "\"><b>" );
                    out.print( name );
                    out.print( "</b></a><div align='right'>" );
                    out.print( (f.length() / 1024) + " KB </div><div>" );
                    i = name.lastIndexOf( '.' ) + 1;
                    if( i > 1 && (name.length() - i) < 6 ) {
                        out.print( name.substring( i ).toUpperCase() + "</div class='ext'>" );
                    } else {
                        out.print( "&nbsp;</div>" );
                    }
                    out.print( "<div style='width: 180'>" );
                    out.print( sdf.format( new Date( f.lastModified() )));
                    out.print( "</div>" );
                }
                out.println( "<br clear='all'>" );
            } else {
                out.print( "<A style=\"width: " + maxLen );
                if( f.isDirectory() ) {
                    out.print( "; height: 18;\" HREF=\"" );
                    out.print( path );
                    out.print( name );
                    out.print( "\"><b>" );
                    out.print( name );
                    out.print( "</b></a>" );
                } else {
                    out.print( ";\" HREF=\"" );
                    out.print( path );
                    out.print( name );
                    out.print( "\"><b>" );
                    out.print( name );
                    out.print( "</b><br><small>" );
                    out.print( (f.length() / 1024) + "KB <br>" );
                    out.print( sdf.format( new Date( f.lastModified() )));
                    out.print( "</small>" );
                    out.println( "</a>" );
                }
            }
        }
View Full Code Here

Examples of com.knowgate.jcifs.smb.SmbFile

                return;
            }
        }

        try {
            SmbFile file;

            if( ntlm != null ) {
                file = new SmbFile( "smb:/" + pathInfo , ntlm );
            } else if( server == null ) {
                file = new SmbFile( "smb://" );
            } else {
                file = new SmbFile( "smb:/" + pathInfo );
            }

            if( file.isDirectory() ) {
                doDirectory( req, resp, file );
            } else {
                doFile( req, resp, file );
            }
        } catch( SmbAuthException sae ) {
View Full Code Here

Examples of jcifs.smb.SmbFile

   * @throws RegainException If the URL's protocol isn't <code>smb://</code>.
   */
  public static SmbFile urlToSmbFile(String url) throws RegainException {

    try {
      return new SmbFile(urlToSmbFileName(url));
    } catch (MalformedURLException urlEx) {
      throw new RegainException(urlEx.getMessage(), urlEx);
    }
  }
View Full Code Here

Examples of jcifs.smb.SmbFile

public class List {

    public static void main( String[] argv ) throws Exception {

        SmbFile file = new SmbFile( argv[0] );

        long t1 = System.currentTimeMillis();
        SmbFile[] files = file.listFiles();
        long t2 = System.currentTimeMillis() - t1;

        for( int i = 0; i < files.length; i++ ) {
            System.out.println( " " + files[i].getURL().toExternalForm()  + " ");
        }
View Full Code Here

Examples of jcifs.smb.SmbFile

   */
  private byte[] loadSmbFile(String url) throws RegainException {
       
    InputStream in = null;
    try {
      SmbFile smbFile = RegainToolkit.urlToSmbFile(
        CrawlerToolkit.replaceAuthenticationValuesInURL(url, mAccountPasswordEntry));
   
      if( smbFile.canRead() && !smbFile.isDirectory() ) {
        in = smbFile.getInputStream();
        mLastModifiedDate = new Date(smbFile.lastModified());
       
        return CrawlerToolkit.loadFileFromStream(in,smbFile.getContentLength());
       
      } else {
        throw new RegainException("Can't load content from: "
        + smbFile.getCanonicalPath());
      }
     
    } catch (Throwable thr) {
      throw new RegainException( thr.getMessage(), thr );
     
View Full Code Here

Examples of jcifs.smb.SmbFile

          throw new RegainException("Creating stream for file failed: " +
              mContentAsFile, thr);
        }
      } else if(mUrl.startsWith("smb://")) {
        try {
           SmbFile smbFile = RegainToolkit.urlToSmbFile(
             CrawlerToolkit.replaceAuthenticationValuesInURL(mUrl, mAccountPasswordEntry));
           return smbFile.getInputStream();
          
        } catch (Throwable thr) {
          throw new RegainException("Creating stream for file failed: " +
              mContentAsFile, thr);
        }
View Full Code Here

Examples of jcifs.smb.SmbFile

          continue;
        }
      } else if (url.startsWith("smb://")) {
        // Windows share: Check whether this is a directory
        try {
          SmbFile smbFile = RegainToolkit.urlToSmbFile(
            CrawlerToolkit.replaceAuthenticationValuesInURL(url,
            CrawlerToolkit.findAuthenticationValuesForURL(url, accountPasswordStore)));
          // Check whether the file is readable.
          if (!smbFile.canRead()) {
            mCrawlerJobProfiler.abortMeasuring();
            logError("File is not readable: '" + url + "'", null, false);
            continue;
          } else if (smbFile.isDirectory()) {
            // This IS a directory -> Add all child files as Jobs
            if (shouldBeParsed) {
              parseSmbDirectory(smbFile);
            }
View Full Code Here

Examples of jcifs.smb.SmbFile

         } else
           path = smbFileName.getUriWithoutAuth();

        NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(
            smbFileName.getDomain(), smbFileName.getUserName(), smbFileName.getPassword());
        SmbFile file = new SmbFile(path, auth);

        if (file.isDirectory() && !file.toString().endsWith("/"))
        {
            file = new SmbFile(path + "/", auth);
        }

        return file;
    }
View Full Code Here

Examples of jcifs.smb.SmbFile

    public URL getURL() throws FileSystemException {
      try {
        file = createSmbFile(getName());

        SmbFile parent = new SmbFile(file.getParent());
        SmbFile[] tmp = parent.listFiles(new SmbFileFilter() {
           public boolean accept(SmbFile f) {
             return f.getName().equals(file.getName());
           }
        });
View Full Code Here

Examples of jcifs.smb.SmbFile

     * @throws MalformedURLException
     */
    public SmbFile getSmbFile() throws MalformedURLException {
        if (!isSMB()) throw new UnsupportedOperationException();
        String url = unescape(this.toNormalform(false, true));
        return new SmbFile(url);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.