Package jcifs.smb

Examples of jcifs.smb.SmbFile


import java.util.GregorianCalendar;

public class GetDate {

    public static void main( String argv[] ) throws Exception {
        SmbFile f = new SmbFile( argv[0] );
        Date d = new Date( f.lastModified() );
        SimpleDateFormat sdf = new SimpleDateFormat( "EEEE, MMMM d, yyyy h:mm:ss a" );
        sdf.setCalendar( new GregorianCalendar() );
        System.out.println( sdf.format( d ));
    }
View Full Code Here


public class ListFiles {

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

        for (int a = 0; a < argv.length; a++) {
            SmbFile file;
            SmbFile[] files = new SmbFile[0];

            file = new SmbFile( argv[a] );

            long t1 = System.currentTimeMillis();
            try {
                files = file.listFiles();
            } catch (Exception e) {
                e.printStackTrace();
            }
            long t2 = System.currentTimeMillis() - t1;
View Full Code Here

public class RenameTo {

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

        SmbFile from = new SmbFile( argv[0] );
        SmbFile to = new SmbFile( argv[1] );
        from.renameTo( to );
    }
View Full Code Here

    static final int SIZE = 0xFFF;

    public static void main( String argv[] ) throws Exception {
        int n, tot;
        byte[] buf = new byte[SIZE];
        SmbFile f = new SmbFile( argv[0] );
        SmbFileOutputStream out = new SmbFileOutputStream( f );

        n = tot = 0;
        do {
            if(( n % 0x1F ) == 0) {
                f = new SmbFile( argv[0] );
                out = new SmbFileOutputStream( f );
                System.out.print( '#' );
            }
            out.write( buf, 0, n );
            out.flush();
View Full Code Here

        if (argv.length < 3) {
            System.err.println( "CrawlTest <url> <numthreads> <maxdepth>" );
            return;
        }

        SmbFile f = new SmbFile( argv[0] );
        int numThreads = Integer.parseInt( argv[1] );
        int maxDepth = Integer.parseInt( argv[2] );

        while (numThreads-- > 0 && System.in.read() == '\n') {
            CrawlTest sc = new CrawlTest( f, maxDepth );
View Full Code Here

      try
      {
        // use NtlmPasswordAuthentication so that we can reuse credential for DFS support
        pa = new NtlmPasswordAuthentication(domain,username,password);
        SmbFile smbconnection = new SmbFile("smb://" + server + "/",pa);
        smbconnectionPath = getFileCanonicalPath(smbconnection);
      }
      catch (MalformedURLException e)
      {
        Logging.connectors.error("Unable to access SMB/CIFS share: "+"smb://" + ((domain==null)?"":domain)+";"+username+":<password>@"+ server + "/\n" + e);
View Full Code Here

      documentIdentifier = documentIdentifiers[i];
      try
      {
        if (Logging.connectors.isDebugEnabled())
          Logging.connectors.debug("JCIFS: getVersions(): documentIdentifiers[" + i + "] is: " + documentIdentifier);
        SmbFile file = new SmbFile(documentIdentifier,pa);

        // File has to exist AND have a non-null canonical path to be readable.  If the canonical path is
        // null, it means that the windows permissions are not right and directory/file is not readable!!!
        String newPath = getFileCanonicalPath(file);
        // We MUST check the specification here, otherwise a recrawl may not delete what it's supposed to!
View Full Code Here

      if (Logging.connectors.isDebugEnabled())
        Logging.connectors.debug("JCIFS: Processing '"+documentIdentifier+"'");
      try
      {

        SmbFile file = new SmbFile(documentIdentifier,pa);

        if (fileExists(file))
        {
          if (fileIsDirectory(file))
          {
            if (Logging.connectors.isDebugEnabled())
              Logging.connectors.debug("JCIFS: '"+documentIdentifier+"' is a directory");

            // Queue up stuff for directory
            // DFS special support no longer needed, because JCifs now does the right thing.

            // This is the string we replace in the child canonical paths.
            // String matchPrefix = "";
            // This is what we replace it with, to get back to a DFS path.
            // String matchReplace = "";

            // DFS resolved.

            // Use a filter to actually do the work here.  This prevents large arrays from being
            // created when there are big directories.
            ProcessDocumentsFilter filter = new ProcessDocumentsFilter(activities,spec);
            fileListFiles(file,filter);
            filter.checkAndThrow();
          }
          else
          {
            if (Logging.connectors.isDebugEnabled())
              Logging.connectors.debug("JCIFS: '"+documentIdentifier+"' is a file");

            if (!scanOnly[i])
            {
              // We've already avoided queuing documents that we
              // don't want, based on file specifications.
              // We still need to check based on file data.

              // DFS support is now implicit in JCifs.

              long startFetchTime = System.currentTimeMillis();
              String fileName = getFileCanonicalPath(file);
              if (fileName != null)
              {
                // manipulate path to include the DFS alias, not the literal path
                // String newPath = matchPrefix + fileName.substring(matchReplace.length());
                String newPath = fileName;
                if (checkNeedFileData(newPath, spec))
                {
                  if (Logging.connectors.isDebugEnabled())
                    Logging.connectors.debug("JCIFS: Local file data needed for '"+documentIdentifier+"'");

                  // Create a temporary file, and use that for the check and then the ingest
                  File tempFile = File.createTempFile("_sdc_",null);
                  try
                  {
                    FileOutputStream os = new FileOutputStream(tempFile);
                    try
                    {

                      // Now, make a local copy so we can fingerprint
                      InputStream inputStream = getFileInputStream(file);
                      try
                      {
                        // Copy!
                        if (transferBuffer == null)
                          transferBuffer = new byte[65536];
                        while (true)
                        {
                          int amt = inputStream.read(transferBuffer,0,transferBuffer.length);
                          if (amt == -1)
                            break;
                          os.write(transferBuffer,0,amt);
                        }
                      }
                      finally
                      {
                        inputStream.close();
                      }
                    }
                    finally
                    {
                      os.close();
                    }


                    if (checkIngest(tempFile, newPath, spec, activities))
                    {
                      if (Logging.connectors.isDebugEnabled())
                        Logging.connectors.debug("JCIFS: Decided to ingest '"+documentIdentifier+"'");
                      // OK, do ingestion itself!
                      InputStream inputStream = new FileInputStream(tempFile);
                      try
                      {
                        RepositoryDocument rd = new RepositoryDocument();
                        rd.setBinary(inputStream, tempFile.length());
                        rd.setFileName(file.getName());
                        int index = 0;
                        index = setDocumentSecurity(rd,version,index);
                        index = setPathMetadata(rd,version,index);
                        StringBuilder ingestURI = new StringBuilder();
                        index = unpack(ingestURI,version,index,'+');
                        activities.ingestDocument(documentIdentifier, version, ingestURI.toString(), rd);
                      }
                      finally
                      {
                        inputStream.close();
                      }

                      // I put this record here deliberately for two reasons:
                      // (1) the other path includes ingestion time, and
                      // (2) if anything fails up to and during ingestion, I want THAT failure record to be written, not this one.
                      // So, really, ACTIVITY_ACCESS is a bit more than just fetch for JCIFS...
                      activities.recordActivity(new Long(startFetchTime),ACTIVITY_ACCESS,
                        new Long(tempFile.length()),documentIdentifier,"Success",null,null);

                    }
                    else
                    {
                      // We must actively remove the document here, because the getDocumentVersions()
                      // method has no way of signalling this, since it does not do the fingerprinting.
                      if (Logging.connectors.isDebugEnabled())
                        Logging.connectors.debug("JCIFS: Decided to remove '"+documentIdentifier+"'");
                      activities.deleteDocument(documentIdentifier, version);
                      // We should record the access here as well, since this is a non-exception way through the code path.
                      // (I noticed that this was not being recorded in the history while fixing 25477.)
                      activities.recordActivity(new Long(startFetchTime),ACTIVITY_ACCESS,
                        new Long(tempFile.length()),documentIdentifier,"Success",null,null);
                    }
                  }
                  finally
                  {
                    tempFile.delete();
                  }
                }
                else
                {
                  if (Logging.connectors.isDebugEnabled())
                    Logging.connectors.debug("JCIFS: Local file data not needed for '"+documentIdentifier+"'");

                  // Presume that since the file was queued that it fulfilled the needed criteria.
                  // Go off and ingest the fast way.

                  // Ingest the document.
                  InputStream inputStream = getFileInputStream(file);
                  try
                  {
                    RepositoryDocument rd = new RepositoryDocument();
                    rd.setBinary(inputStream, fileLength(file));
                    rd.setFileName(file.getName());
                    int index = 0;
                    index = setDocumentSecurity(rd,version,index);
                    index = setPathMetadata(rd,version,index);
                    StringBuilder ingestURI = new StringBuilder();
                    index = unpack(ingestURI,version,index,'+');
View Full Code Here

  public String check()
    throws ManifoldCFException
  {
    getSession();
    String serverURI = smbconnectionPath;
    SmbFile server = null;
    try
    {
      server = new SmbFile(serverURI,pa);
    }
    catch (MalformedURLException e1)
    {
      return "Malformed URL: '"+serverURI+"': "+e1.getMessage();
    }
    try
    {
      // check to make sure it's a server or a folder
      int type = getFileType(server);
      if (type==SmbFile.TYPE_SERVER || type==SmbFile.TYPE_SHARE
        || type==SmbFile.TYPE_FILESYSTEM)
      {
        try
        {
          server.connect();
          if (!server.exists())
            return "Server or path does not exist";
        }
        catch (java.net.SocketTimeoutException e)
        {
          return "Timeout connecting to server: "+e.getMessage();
View Full Code Here

  protected String mapToIdentifier(String path)
    throws IOException
  {
    String smburi = smbconnectionPath;
    String uri = smburi + path + "/";
    return getFileCanonicalPath(new SmbFile(uri,pa));
  }
View Full Code Here

TOP

Related Classes of jcifs.smb.SmbFile

Copyright © 2018 www.massapicom. 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.