Class SmbFile

  • Direct Known Subclasses:
    SmbNamedPipe

    public class SmbFile
    extends URLConnection
    This class represents a resource on an SMB network. Mainly these resources are files and directories however an SmbFile may also refer to servers and workgroups. If the resource is a file or directory the methods of SmbFile follow the behavior of the well known File class. One fundamental difference is the usage of a URL scheme [1] to specify the target file or directory. SmbFile URLs have the following syntax:
         smb1://[[[domain;]username[:password]@]server[:port]/[[share/[dir/]file]]][?param=value[param2=value2[...]]]
     
    This example:
         smb1://storage15/public/foo.txt
     
    would reference the file foo.txt in the share public on the server storage15. In addition to referencing files and directories, jCIFS can also address servers, and workgroups.

    Important: all SMB URLs that represent workgroups, servers, shares, or directories require a trailing slash '/'.

    When using the java.net.URL class with 'smb1://' URLs it is necessary to first call the static jcifs.smb1.Config.registerSmbURLHandler(); method. This is required to register the SMB protocol handler.

    The userinfo component of the SMB URL (domain;user:pass) must be URL encoded if it contains reserved characters. According to RFC 2396 these characters are non US-ASCII characters and most meta characters however jCIFS will work correctly with anything but '@' which is used to delimit the userinfo component from the server and '%' which is the URL escape character itself.

    The server component may a traditional NetBIOS name, a DNS name, or IP address. These name resolution mechanisms and their resolution order can be changed (See Setting Name Resolution Properties). The servername and path components are not case sensitive but the domain, username, and password components are. It is also likely that properties must be specified for jcifs.smb1 to function (See Setting JCIFS Properties). Here are some examples of SMB URLs with brief descriptions of what they do:

    [1] This URL scheme is based largely on the SMB Filesharing URL Scheme IETF draft.

    SMB URL Examples
    URLDescription
    smb1://users-nyc;miallen:mypass@angus/tmp/ This URL references a share called tmp on the server angus as user miallen who's password is mypass.
    smb1://Administrator:P%40ss@msmith1/c/WINDOWS/Desktop/foo.txt A relativly sophisticated example that references a file msmith1's desktop as user Administrator. Notice the '@' is URL encoded with the '%40' hexcode escape.
    smb1://angus/ This references only a server. The behavior of some methods is different in this context(e.g. you cannot delete a server) however as you might expect the list method will list the available shares on this server.
    smb1://myworkgroup/ This syntactically is identical to the above example. However if myworkgroup happends to be a workgroup(which is indeed suggested by the name) the list method will return a list of servers that have registered themselves as members of myworkgroup.
    smb1:// Just as smb1://server/ lists shares and smb1://workgroup/ lists servers, the smb1:// URL lists all available workgroups on a netbios LAN. Again, in this context many methods are not valid and return default values(e.g. isHidden will always return false).
    smb1://angus.foo.net/d/jcifs/smb1/pipes.doc The server name may also be a DNS name as it is in this example. See Setting Name Resolution Properties for details.
    smb1://192.168.1.15/ADMIN$/ The server name may also be an IP address. See Setting Name Resolution Properties for details.
    smb1://domain;username:password@server/share/path/to/file.txt A prototypical example that uses all the fields.
    smb1://myworkgroup/angus/ <-- ILLEGAL Despite the hierarchial relationship between workgroups, servers, and filesystems this example is not valid.
    smb1://server/share/path/to/dir <-- ILLEGAL URLs that represent workgroups, servers, shares, or directories require a trailing slash '/'.
    smb1://MYGROUP/?SERVER=192.168.10.15 SMB URLs support some query string parameters. In this example the SERVER parameter is used to override the server name service lookup to contact the server 192.168.10.15 (presumably known to be a master browser) for the server list in workgroup MYGROUP.

    A second constructor argument may be specified to augment the URL for better programmatic control when processing many files under a common base. This is slightly different from the corresponding java.io.File usage; a '/' at the beginning of the second parameter will still use the server component of the first parameter. The examples below illustrate the resulting URLs when this second contructor argument is used.

    Examples Of SMB URLs When Augmented With A Second Constructor Parameter
    First ParameterSecond ParameterResult
    smb1://host/share/a/b/ c/d/ smb1://host/share/a/b/c/d/
    smb1://host/share/foo/bar/ /share2/zig/zag smb1://host/share2/zig/zag
    smb1://host/share/foo/bar/ ../zip/ smb1://host/share/foo/zip/
    smb1://host/share/zig/zag smb1://foo/bar/ smb1://foo/bar/
    smb1://host/share/foo/ ../.././.././../foo/ smb1://host/foo/
    smb1://host/share/zig/zag / smb1://host/
    smb1://server/ ../ smb1://server/
    smb1:// myworkgroup/ smb1://myworkgroup/
    smb1://myworkgroup/ angus/ smb1://myworkgroup/angus/ <-- ILLEGAL
    (But if you first create an SmbFile with 'smb1://workgroup/' and use and use it as the first parameter to a constructor that accepts it with a second String parameter jCIFS will factor out the 'workgroup'.)

    Instances of the SmbFile class are immutable; that is, once created, the abstract pathname represented by an SmbFile object will never change.

    See Also:
    File
    • Field Detail

      • FILE_NO_SHARE

        public static final int FILE_NO_SHARE
        When specified as the shareAccess constructor parameter, other SMB clients (including other threads making calls into jCIFS) will not be permitted to access the target file and will receive "The file is being accessed by another process" message.
        See Also:
        Constant Field Values
      • FILE_SHARE_READ

        public static final int FILE_SHARE_READ
        When specified as the shareAccess constructor parameter, other SMB clients will be permitted to read from the target file while this file is open. This constant may be logically OR'd with other share access flags.
        See Also:
        Constant Field Values
      • FILE_SHARE_WRITE

        public static final int FILE_SHARE_WRITE
        When specified as the shareAccess constructor parameter, other SMB clients will be permitted to write to the target file while this file is open. This constant may be logically OR'd with other share access flags.
        See Also:
        Constant Field Values
      • FILE_SHARE_DELETE

        public static final int FILE_SHARE_DELETE
        When specified as the shareAccess constructor parameter, other SMB clients will be permitted to delete the target file while this file is open. This constant may be logically OR'd with other share access flags.
        See Also:
        Constant Field Values
      • ATTR_READONLY

        public static final int ATTR_READONLY
        A file with this bit on as returned by getAttributes() or set with setAttributes() will be read-only
        See Also:
        Constant Field Values
      • ATTR_HIDDEN

        public static final int ATTR_HIDDEN
        A file with this bit on as returned by getAttributes() or set with setAttributes() will be hidden
        See Also:
        Constant Field Values
      • ATTR_SYSTEM

        public static final int ATTR_SYSTEM
        A file with this bit on as returned by getAttributes() or set with setAttributes() will be a system file
        See Also:
        Constant Field Values
      • ATTR_VOLUME

        public static final int ATTR_VOLUME
        A file with this bit on as returned by getAttributes() is a volume
        See Also:
        Constant Field Values
      • ATTR_DIRECTORY

        public static final int ATTR_DIRECTORY
        A file with this bit on as returned by getAttributes() is a directory
        See Also:
        Constant Field Values
      • ATTR_ARCHIVE

        public static final int ATTR_ARCHIVE
        A file with this bit on as returned by getAttributes() or set with setAttributes() is an archived file
        See Also:
        Constant Field Values
      • TYPE_FILESYSTEM

        public static final int TYPE_FILESYSTEM
        Returned by getType() if the resource this SmbFile represents is a regular file or directory.
        See Also:
        Constant Field Values
      • TYPE_WORKGROUP

        public static final int TYPE_WORKGROUP
        Returned by getType() if the resource this SmbFile represents is a workgroup.
        See Also:
        Constant Field Values
      • TYPE_SERVER

        public static final int TYPE_SERVER
        Returned by getType() if the resource this SmbFile represents is a server.
        See Also:
        Constant Field Values
      • TYPE_SHARE

        public static final int TYPE_SHARE
        Returned by getType() if the resource this SmbFile represents is a share.
        See Also:
        Constant Field Values
      • TYPE_NAMED_PIPE

        public static final int TYPE_NAMED_PIPE
        Returned by getType() if the resource this SmbFile represents is a named pipe.
        See Also:
        Constant Field Values
      • TYPE_PRINTER

        public static final int TYPE_PRINTER
        Returned by getType() if the resource this SmbFile represents is a printer.
        See Also:
        Constant Field Values
      • TYPE_COMM

        public static final int TYPE_COMM
        Returned by getType() if the resource this SmbFile represents is a communications device.
        See Also:
        Constant Field Values
      • dfs

        protected static Dfs dfs
      • DEFAULT_RESPONSE_TIMEOUT

        public static final int DEFAULT_RESPONSE_TIMEOUT
        See Also:
        Constant Field Values
      • LPORT

        public static final int LPORT
      • MAX_MPX_COUNT

        public static final int MAX_MPX_COUNT
      • SND_BUF_SIZE

        public static final int SND_BUF_SIZE
      • RCV_BUF_SIZE

        public static final int RCV_BUF_SIZE
      • USE_UNICODE

        public static final boolean USE_UNICODE
      • FORCE_UNICODE

        public static final boolean FORCE_UNICODE
      • USE_NTSTATUS

        public static final boolean USE_NTSTATUS
      • SIGNPREF

        public static final boolean SIGNPREF
      • USE_NTSMBS

        public static final boolean USE_NTSMBS
      • USE_EXTSEC

        public static final boolean USE_EXTSEC
      • NETBIOS_HOSTNAME

        public static final String NETBIOS_HOSTNAME
      • LM_COMPATIBILITY

        public static final int LM_COMPATIBILITY
      • FLAGS_LOCK_AND_READ_WRITE_AND_UNLOCK

        public static final int FLAGS_LOCK_AND_READ_WRITE_AND_UNLOCK
        See Also:
        Constant Field Values
      • FLAGS_RECEIVE_BUFFER_POSTED

        public static final int FLAGS_RECEIVE_BUFFER_POSTED
        See Also:
        Constant Field Values
      • FLAGS_PATH_NAMES_CASELESS

        public static final int FLAGS_PATH_NAMES_CASELESS
        See Also:
        Constant Field Values
      • FLAGS_PATH_NAMES_CANONICALIZED

        public static final int FLAGS_PATH_NAMES_CANONICALIZED
        See Also:
        Constant Field Values
      • FLAGS_OPLOCK_REQUESTED_OR_GRANTED

        public static final int FLAGS_OPLOCK_REQUESTED_OR_GRANTED
        See Also:
        Constant Field Values
      • FLAGS_NOTIFY_OF_MODIFY_ACTION

        public static final int FLAGS_NOTIFY_OF_MODIFY_ACTION
        See Also:
        Constant Field Values
      • FLAGS2_EXTENDED_ATTRIBUTES

        public static final int FLAGS2_EXTENDED_ATTRIBUTES
        See Also:
        Constant Field Values
      • FLAGS2_SECURITY_SIGNATURES

        public static final int FLAGS2_SECURITY_SIGNATURES
        See Also:
        Constant Field Values
      • FLAGS2_EXTENDED_SECURITY_NEGOTIATION

        public static final int FLAGS2_EXTENDED_SECURITY_NEGOTIATION
        See Also:
        Constant Field Values
      • FLAGS2_RESOLVE_PATHS_IN_DFS

        public static final int FLAGS2_RESOLVE_PATHS_IN_DFS
        See Also:
        Constant Field Values
      • FLAGS2_PERMIT_READ_IF_EXECUTE_PERM

        public static final int FLAGS2_PERMIT_READ_IF_EXECUTE_PERM
        See Also:
        Constant Field Values
      • FLAGS_TARGET_MUST_BE_FILE

        public static final int FLAGS_TARGET_MUST_BE_FILE
        See Also:
        Constant Field Values
      • FLAGS_TARGET_MUST_BE_DIRECTORY

        public static final int FLAGS_TARGET_MUST_BE_DIRECTORY
        See Also:
        Constant Field Values
      • FLAGS_COPY_TARGET_MODE_ASCII

        public static final int FLAGS_COPY_TARGET_MODE_ASCII
        See Also:
        Constant Field Values
      • FLAGS_COPY_SOURCE_MODE_ASCII

        public static final int FLAGS_COPY_SOURCE_MODE_ASCII
        See Also:
        Constant Field Values
      • FLAGS_VERIFY_ALL_WRITES

        public static final int FLAGS_VERIFY_ALL_WRITES
        See Also:
        Constant Field Values
      • OPEN_FUNCTION_FAIL_IF_EXISTS

        public static final int OPEN_FUNCTION_FAIL_IF_EXISTS
        See Also:
        Constant Field Values
      • OPEN_FUNCTION_OVERWRITE_IF_EXISTS

        public static final int OPEN_FUNCTION_OVERWRITE_IF_EXISTS
        See Also:
        Constant Field Values
      • PID

        public static final int PID
      • MILLISECONDS_BETWEEN_1970_AND_1601

        public static final long MILLISECONDS_BETWEEN_1970_AND_1601
        See Also:
        Constant Field Values
      • USE_BATCHING

        public static final boolean USE_BATCHING
      • OEM_ENCODING

        public static final String OEM_ENCODING
      • DEFAULT_FLAGS2

        public static final int DEFAULT_FLAGS2
      • DEFAULT_CAPABILITIES

        public static final int DEFAULT_CAPABILITIES
      • FLAGS2

        public static final int FLAGS2
      • CAPABILITIES

        public static final int CAPABILITIES
      • TCP_NODELAY

        public static final boolean TCP_NODELAY
      • RESPONSE_TIMEOUT

        public static final int RESPONSE_TIMEOUT
      • CONNECTIONS

        public static final LinkedList CONNECTIONS
      • SSN_LIMIT

        public static final int SSN_LIMIT
      • SO_TIMEOUT

        public static final int SO_TIMEOUT
      • CONN_TIMEOUT

        public static final int CONN_TIMEOUT
      • NATIVE_OS

        public static final String NATIVE_OS
      • NATIVE_LANMAN

        public static final String NATIVE_LANMAN
      • NULL_TRANSPORT

        public static final SmbTransport NULL_TRANSPORT
    • Constructor Detail

      • SmbFile

        public SmbFile​(String url)
                throws MalformedURLException
        Constructs an SmbFile representing a resource on an SMB network such as a file or directory. See the description and examples of smb URLs above.
        Parameters:
        url - A URL string
        Throws:
        MalformedURLException - If the parent and child parameters do not follow the prescribed syntax
      • SmbFile

        public SmbFile​(SmbFile context,
                       String name)
                throws MalformedURLException,
                       UnknownHostException
        Constructs an SmbFile representing a resource on an SMB network such as a file or directory. The second parameter is a relative path from the parent SmbFile. See the description above for examples of using the second name parameter.
        Parameters:
        context - A base SmbFile
        name - A path string relative to the parent paremeter
        Throws:
        MalformedURLException - If the parent and child parameters do not follow the prescribed syntax
        UnknownHostException - If the server or workgroup of the context file cannot be determined
      • SmbFile

        public SmbFile​(String context,
                       String name)
                throws MalformedURLException
        Constructs an SmbFile representing a resource on an SMB network such as a file or directory. The second parameter is a relative path from the parent. See the description above for examples of using the second chile parameter.
        Parameters:
        context - A URL string
        name - A path string relative to the context paremeter
        Throws:
        MalformedURLException - If the context and name parameters do not follow the prescribed syntax
      • SmbFile

        public SmbFile​(String url,
                       NtlmPasswordAuthentication auth)
                throws MalformedURLException
        Constructs an SmbFile representing a resource on an SMB network such as a file or directory.
        Parameters:
        url - A URL string
        auth - The credentials the client should use for authentication
        Throws:
        MalformedURLException - If the url parameter does not follow the prescribed syntax
      • SmbFile

        public SmbFile​(String url,
                       NtlmPasswordAuthentication auth,
                       int shareAccess)
                throws MalformedURLException
        Constructs an SmbFile representing a file on an SMB network. The shareAccess parameter controls what permissions other clients have when trying to access the same file while this instance is still open. This value is either FILE_NO_SHARE or any combination of FILE_SHARE_READ, FILE_SHARE_WRITE, and FILE_SHARE_DELETE logically OR'd together.
        Parameters:
        url - A URL string
        auth - The credentials the client should use for authentication
        shareAccess - Specifies what access other clients have while this file is open.
        Throws:
        MalformedURLException - If the url parameter does not follow the prescribed syntax
      • SmbFile

        public SmbFile​(String context,
                       String name,
                       NtlmPasswordAuthentication auth)
                throws MalformedURLException
        Constructs an SmbFile representing a resource on an SMB network such as a file or directory. The second parameter is a relative path from the context. See the description above for examples of using the second name parameter.
        Parameters:
        context - A URL string
        name - A path string relative to the context paremeter
        auth - The credentials the client should use for authentication
        Throws:
        MalformedURLException - If the context and name parameters do not follow the prescribed syntax
      • SmbFile

        public SmbFile​(String context,
                       String name,
                       NtlmPasswordAuthentication auth,
                       int shareAccess)
                throws MalformedURLException
        Constructs an SmbFile representing a resource on an SMB network such as a file or directory. The second parameter is a relative path from the context. See the description above for examples of using the second name parameter. The shareAccess parameter controls what permissions other clients have when trying to access the same file while this instance is still open. This value is either FILE_NO_SHARE or any combination of FILE_SHARE_READ, FILE_SHARE_WRITE, and FILE_SHARE_DELETE logically OR'd together.
        Parameters:
        context - A URL string
        name - A path string relative to the context paremeter
        auth - The credentials the client should use for authentication
        shareAccess - Specifies what access other clients have while this file is open.
        Throws:
        MalformedURLException - If the context and name parameters do not follow the prescribed syntax
      • SmbFile

        public SmbFile​(SmbFile context,
                       String name,
                       int shareAccess)
                throws MalformedURLException,
                       UnknownHostException
        Constructs an SmbFile representing a resource on an SMB network such as a file or directory. The second parameter is a relative path from the context. See the description above for examples of using the second name parameter. The shareAccess parameter controls what permissions other clients have when trying to access the same file while this instance is still open. This value is either FILE_NO_SHARE or any combination of FILE_SHARE_READ, FILE_SHARE_WRITE, and FILE_SHARE_DELETE logically OR'd together.
        Parameters:
        context - A base SmbFile
        name - A path string relative to the context file path
        shareAccess - Specifies what access other clients have while this file is open.
        Throws:
        MalformedURLException - If the context and name parameters do not follow the prescribed syntax
        UnknownHostException
      • SmbFile

        public SmbFile​(URL url)
        Constructs an SmbFile representing a resource on an SMB network such as a file or directory from a URL object.
        Parameters:
        url - The URL of the target resource
      • SmbFile

        public SmbFile​(URL url,
                       NtlmPasswordAuthentication auth)
        Constructs an SmbFile representing a resource on an SMB network such as a file or directory from a URL object and an NtlmPasswordAuthentication object.
        Parameters:
        url - The URL of the target resource
        auth - The credentials the client should use for authentication
    • Method Detail

      • connect

        public void connect()
                     throws IOException
        It is not necessary to call this method directly. This is the URLConnection implementation of connect().
        Specified by:
        connect in class URLConnection
        Throws:
        IOException
      • getPrincipal

        public Principal getPrincipal()
        Returns the NtlmPasswordAuthentication object used as credentials with this file or pipe. This can be used to retrieve the username for example: String username = f.getPrincipal().getName(); The Principal object returned will never be null however the username can be null indication anonymous credentials were used (e.g. some IPC$ services).
      • getName

        public String getName()
        Returns the last component of the target URL. This will effectively be the name of the file or directory represented by this SmbFile or in the case of URLs that only specify a server or workgroup, the server or workgroup will be returned. The name of the root URL smb1:// is also smb1://. If this SmbFile refers to a workgroup, server, share, or directory, the name will include a trailing slash '/' so that composing new SmbFiles will maintain the trailing slash requirement.
        Returns:
        The last component of the URL associated with this SMB resource or smb1:// if the resource is smb1:// itself.
      • getParent

        public String getParent()
        Everything but the last component of the URL representing this SMB resource is effectivly it's parent. The root URL smb1:// does not have a parent. In this case smb1:// is returned.
        Returns:
        The parent directory of this SMB resource or smb1:// if the resource refers to the root of the URL hierarchy which incedentally is also smb1://.
      • getPath

        public String getPath()
        Returns the full uncanonicalized URL of this SMB resource. An SmbFile constructed with the result of this method will result in an SmbFile that is equal to the original.
        Returns:
        The uncanonicalized full URL of this SMB resource.
      • getUncPath

        public String getUncPath()
        Retuns the Windows UNC style path with backslashs intead of forward slashes.
        Returns:
        The UNC path.
      • getCanonicalPath

        public String getCanonicalPath()
        Returns the full URL of this SMB resource with '.' and '..' components factored out. An SmbFile constructed with the result of this method will result in an SmbFile that is equal to the original.
        Returns:
        The canonicalized URL of this SMB resource.
      • getShare

        public String getShare()
        Retrieves the share associated with this SMB resource. In the case of smb1://, smb1://workgroup/, and smb1://server/ URLs which do not specify a share, null will be returned.
        Returns:
        The share component or null if there is no share
      • getServer

        public String getServer()
        Retrieve the hostname of the server for this SMB resource. If this SmbFile references a workgroup, the name of the workgroup is returned. If this SmbFile refers to the root of this SMB network hierarchy, null is returned.
        Returns:
        The server or workgroup name or null if this SmbFile refers to the root smb1:// resource.
      • getType

        public int getType()
                    throws SmbException
        Returns type of of object this SmbFile represents.
        Returns:
        TYPE_FILESYSTEM, TYPE_WORKGROUP, TYPE_SERVER, TYPE_SHARE, TYPE_PRINTER, TYPE_NAMED_PIPE, or TYPE_COMM.
        Throws:
        SmbException
      • exists

        public boolean exists()
                       throws SmbException
        Tests to see if the SMB resource exists. If the resource refers only to a server, this method determines if the server exists on the network and is advertising SMB services. If this resource refers to a workgroup, this method determines if the workgroup name is valid on the local SMB network. If this SmbFile refers to the root smb1:// resource true is always returned. If this SmbFile is a traditional file or directory, it will be queried for on the specified server as expected.
        Returns:
        true if the resource exists or is alive or false otherwise
        Throws:
        SmbException
      • canRead

        public boolean canRead()
                        throws SmbException
        Tests to see if the file this SmbFile represents can be read. Because any file, directory, or other resource can be read if it exists, this method simply calls the exists method.
        Returns:
        true if the file is read-only
        Throws:
        SmbException
      • canWrite

        public boolean canWrite()
                         throws SmbException
        Tests to see if the file this SmbFile represents exists and is not marked read-only. By default, resources are considered to be read-only and therefore for smb1://, smb1://workgroup/, and smb1://server/ resources will be read-only.
        Returns:
        true if the resource exists is not marked read-only
        Throws:
        SmbException
      • isDirectory

        public boolean isDirectory()
                            throws SmbException
        Tests to see if the file this SmbFile represents is a directory.
        Returns:
        true if this SmbFile is a directory
        Throws:
        SmbException
      • isFile

        public boolean isFile()
                       throws SmbException
        Tests to see if the file this SmbFile represents is not a directory.
        Returns:
        true if this SmbFile is not a directory
        Throws:
        SmbException
      • isHidden

        public boolean isHidden()
                         throws SmbException
        Tests to see if the file this SmbFile represents is marked as hidden. This method will also return true for shares with names that end with '$' such as IPC$ or C$.
        Returns:
        true if the SmbFile is marked as being hidden
        Throws:
        SmbException
      • getDfsPath

        public String getDfsPath()
                          throws SmbException
        If the path of this SmbFile falls within a DFS volume, this method will return the referral path to which it maps. Otherwise null is returned.
        Throws:
        SmbException
      • createTime

        public long createTime()
                        throws SmbException
        Retrieve the time this SmbFile was created. The value returned is suitable for constructing a Date object (i.e. seconds since Epoch 1970). Times should be the same as those reported using the properties dialog of the Windows Explorer program. For Win95/98/Me this is actually the last write time. It is currently not possible to retrieve the create time from files on these systems.
        Returns:
        The number of milliseconds since the 00:00:00 GMT, January 1, 1970 as a long value
        Throws:
        SmbException
      • lastModified

        public long lastModified()
                          throws SmbException
        Retrieve the last time the file represented by this SmbFile was modified. The value returned is suitable for constructing a Date object (i.e. seconds since Epoch 1970). Times should be the same as those reported using the properties dialog of the Windows Explorer program.
        Returns:
        The number of milliseconds since the 00:00:00 GMT, January 1, 1970 as a long value
        Throws:
        SmbException
      • list

        public String[] list()
                      throws SmbException
        List the contents of this SMB resource. The list returned by this method will be;
        • files and directories contained within this resource if the resource is a normal disk file directory,
        • all available NetBIOS workgroups or domains if this resource is the top level URL smb1://,
        • all servers registered as members of a NetBIOS workgroup if this resource refers to a workgroup in a smb1://workgroup/ URL,
        • all browseable shares of a server including printers, IPC services, or disk volumes if this resource is a server URL in the form smb1://server/,
        • or null if the resource cannot be resolved.
        Returns:
        A String[] array of files and directories, workgroups, servers, or shares depending on the context of the resource URL
        Throws:
        SmbException
      • list

        public String[] list​(SmbFilenameFilter filter)
                      throws SmbException
        List the contents of this SMB resource. The list returned will be identical to the list returned by the parameterless list() method minus filenames filtered by the specified filter.
        Parameters:
        filter - a filename filter to exclude filenames from the results
        Throws:
        SmbException - # @return An array of filenames
      • listFiles

        public SmbFile[] listFiles()
                            throws SmbException
        List the contents of this SMB resource as an array of SmbFile objects. This method is much more efficient than the regular list method when querying attributes of each file in the result set.

        The list of SmbFiles returned by this method will be;

        • files and directories contained within this resource if the resource is a normal disk file directory,
        • all available NetBIOS workgroups or domains if this resource is the top level URL smb1://,
        • all servers registered as members of a NetBIOS workgroup if this resource refers to a workgroup in a smb1://workgroup/ URL,
        • all browseable shares of a server including printers, IPC services, or disk volumes if this resource is a server URL in the form smb1://server/,
        • or null if the resource cannot be resolved.
        Returns:
        An array of SmbFile objects representing file and directories, workgroups, servers, or shares depending on the context of the resource URL
        Throws:
        SmbException
      • listFiles

        public SmbFile[] listFiles​(String wildcard)
                            throws SmbException
        The CIFS protocol provides for DOS "wildcards" to be used as a performance enhancement. The client does not have to filter the names and the server does not have to return all directory entries.

        The wildcard expression may consist of two special meta characters in addition to the normal filename characters. The '*' character matches any number of characters in part of a name. If the expression begins with one or more '?'s then exactly that many characters will be matched whereas if it ends with '?'s it will match that many characters or less.

        Wildcard expressions will not filter workgroup names or server names.

         winnt> ls c?o*
         clock.avi                  -rw--      82944 Mon Oct 14 1996 1:38 AM
         Cookies                    drw--          0 Fri Nov 13 1998 9:42 PM
         2 items in 5ms
         
        Parameters:
        wildcard - a wildcard expression
        Returns:
        An array of SmbFile objects representing file and directories, workgroups, servers, or shares depending on the context of the resource URL
        Throws:
        SmbException
      • listFiles

        public SmbFile[] listFiles​(SmbFilenameFilter filter)
                            throws SmbException
        List the contents of this SMB resource. The list returned will be identical to the list returned by the parameterless listFiles() method minus files filtered by the specified filename filter.
        Parameters:
        filter - a filter to exclude files from the results
        Returns:
        An array of SmbFile objects
        Throws:
        SmbException
      • listFiles

        public SmbFile[] listFiles​(SmbFileFilter filter)
                            throws SmbException
        List the contents of this SMB resource. The list returned will be identical to the list returned by the parameterless listFiles() method minus filenames filtered by the specified filter.
        Parameters:
        filter - a file filter to exclude files from the results
        Returns:
        An array of SmbFile objects
        Throws:
        SmbException
      • renameTo

        public void renameTo​(SmbFile dest)
                      throws SmbException
        Changes the name of the file this SmbFile represents to the name designated by the SmbFile argument.

        Remember: SmbFiles are immutible and therefore the path associated with this SmbFile object will not change). To access the renamed file it is necessary to construct a new SmbFile.

        Parameters:
        dest - An SmbFile that represents the new pathname
        Throws:
        NullPointerException - If the dest argument is null
        SmbException
      • copyTo

        public void copyTo​(SmbFile dest)
                    throws SmbException
        This method will copy the file or directory represented by this SmbFile and it's sub-contents to the location specified by the dest parameter. This file and the destination file do not need to be on the same host. This operation does not copy extended file attibutes such as ACLs but it does copy regular attributes as well as create and last write times. This method is almost twice as efficient as manually copying as it employs an additional write thread to read and write data concurrently.

        It is not possible (nor meaningful) to copy entire workgroups or servers.

        Parameters:
        dest - the destination file or directory
        Throws:
        SmbException
      • delete

        public void delete()
                    throws SmbException
        This method will delete the file or directory specified by this SmbFile. If the target is a directory, the contents of the directory will be deleted as well. If a file within the directory or it's sub-directories is marked read-only, the read-only status will be removed and the file will be deleted.
        Throws:
        SmbException
      • length

        public long length()
                    throws SmbException
        Returns the length of this SmbFile in bytes. If this object is a TYPE_SHARE the total capacity of the disk shared in bytes is returned. If this object is a directory or a type other than TYPE_SHARE, 0L is returned.
        Returns:
        The length of the file in bytes or 0 if this SmbFile is not a file.
        Throws:
        SmbException
      • getDiskFreeSpace

        public long getDiskFreeSpace()
                              throws SmbException
        This method returns the free disk space in bytes of the drive this share represents or the drive on which the directory or file resides. Objects other than TYPE_SHARE or TYPE_FILESYSTEM will result in 0L being returned.
        Returns:
        the free disk space in bytes of the drive on which this file or directory resides
        Throws:
        SmbException
      • mkdir

        public void mkdir()
                   throws SmbException
        Creates a directory with the path specified by this SmbFile. For this method to be successful, the target must not already exist. This method will fail when used with smb1://, smb1://workgroup/, smb1://server/, or smb1://server/share/ URLs because workgroups, servers, and shares cannot be dynamically created (although in the future it may be possible to create shares).
        Throws:
        SmbException
      • mkdirs

        public void mkdirs()
                    throws SmbException
        Creates a directory with the path specified by this SmbFile and any parent directories that do not exist. This method will fail when used with smb1://, smb1://workgroup/, smb1://server/, or smb1://server/share/ URLs because workgroups, servers, and shares cannot be dynamically created (although in the future it may be possible to create shares).
        Throws:
        SmbException
      • createNewFile

        public void createNewFile()
                           throws SmbException
        Create a new file but fail if it already exists. The check for existance of the file and it's creation are an atomic operation with respect to other filesystem activities.
        Throws:
        SmbException
      • setCreateTime

        public void setCreateTime​(long time)
                           throws SmbException
        Set the create time of the file. The time is specified as milliseconds from Jan 1, 1970 which is the same as that which is returned by the createTime() method.

        This method does not apply to workgroups, servers, or shares.

        Parameters:
        time - the create time as milliseconds since Jan 1, 1970
        Throws:
        SmbException
      • setLastModified

        public void setLastModified​(long time)
                             throws SmbException
        Set the last modified time of the file. The time is specified as milliseconds from Jan 1, 1970 which is the same as that which is returned by the lastModified(), getLastModified(), and getDate() methods.

        This method does not apply to workgroups, servers, or shares.

        Parameters:
        time - the last modified time as milliseconds since Jan 1, 1970
        Throws:
        SmbException
      • getAttributes

        public int getAttributes()
                          throws SmbException
        Return the attributes of this file. Attributes are represented as a bitset that must be masked with ATTR_* constants to determine if they are set or unset. The value returned is suitable for use with the setAttributes() method.
        Returns:
        the ATTR_* attributes associated with this file
        Throws:
        SmbException
      • setAttributes

        public void setAttributes​(int attrs)
                           throws SmbException
        Set the attributes of this file. Attributes are composed into a bitset by bitwise ORing the ATTR_* constants. Setting the value returned by getAttributes will result in both files having the same attributes.
        Throws:
        SmbException
      • setReadOnly

        public void setReadOnly()
                         throws SmbException
        Make this file read-only. This is shorthand for setAttributes( getAttributes() | ATTR_READ_ONLY ).
        Throws:
        SmbException
      • setReadWrite

        public void setReadWrite()
                          throws SmbException
        Turn off the read-only attribute of this file. This is shorthand for setAttributes( getAttributes() & ~ATTR_READONLY ).
        Throws:
        SmbException
      • toURL

        public URL toURL()
                  throws MalformedURLException
        Deprecated.
        Use getURL() instead
        Returns a URL for this SmbFile. The URL may be used as any other URL might to access an SMB resource. Currently only retrieving data and information is supported (i.e. no doOutput).
        Returns:
        A new URL for this SmbFile
        Throws:
        MalformedURLException
      • hashCode

        public int hashCode()
        Computes a hashCode for this file based on the URL string and IP address if the server. The hashing function uses the hashcode of the server address, the canonical representation of the URL, and does not compare authentication information. In essance, two SmbFile objects that refer to the same file should generate the same hashcode provided it is possible to make such a determination.
        Overrides:
        hashCode in class Object
        Returns:
        A hashcode for this abstract file
        Throws:
        SmbException
      • pathNamesPossiblyEqual

        protected boolean pathNamesPossiblyEqual​(String path1,
                                                 String path2)
      • equals

        public boolean equals​(Object obj)
        Tests to see if two SmbFile objects are equal. Two SmbFile objects are equal when they reference the same SMB resource. More specifically, two SmbFile objects are equals if their server IP addresses are equal and the canonicalized representation of their URLs, minus authentication parameters, are case insensitivly and lexographically equal.

        For example, assuming the server angus resolves to the 192.168.1.15 IP address, the below URLs would result in SmbFiles that are equal.

         smb1://192.168.1.15/share/DIR/foo.txt
         smb1://angus/share/data/../dir/foo.txt
         
        Overrides:
        equals in class Object
        Parameters:
        obj - Another SmbFile object to compare for equality
        Returns:
        true if the two objects refer to the same SMB resource and false otherwise
        Throws:
        SmbException
      • toString

        public String toString()
        Returns the string representation of this SmbFile object. This will be the same as the URL used to construct this SmbFile. This method will return the same value as getPath.
        Overrides:
        toString in class URLConnection
        Returns:
        The original URL representation of this SMB resource
        Throws:
        SmbException
      • getContentLength

        public int getContentLength()
        This URLConnection method just returns the result of length().
        Overrides:
        getContentLength in class URLConnection
        Returns:
        the length of this file or 0 if it refers to a directory
      • getDate

        public long getDate()
        This URLConnection method just returns the result of lastModified.
        Overrides:
        getDate in class URLConnection
        Returns:
        the last modified data as milliseconds since Jan 1, 1970
      • getLastModified

        public long getLastModified()
        This URLConnection method just returns the result of lastModified.
        Overrides:
        getLastModified in class URLConnection
        Returns:
        the last modified data as milliseconds since Jan 1, 1970
      • getSecurity

        public ACE[] getSecurity​(boolean resolveSids)
                          throws IOException
        Return an array of Access Control Entry (ACE) objects representing the security descriptor associated with this file or directory. If no DACL is present, null is returned. If the DACL is empty, an array with 0 elements is returned.
        Parameters:
        resolveSids - Attempt to resolve the SIDs within each ACE form their numeric representation to their corresponding account names.
        Throws:
        IOException
      • getShareSecurity

        public ACE[] getShareSecurity​(boolean resolveSids)
                               throws IOException
        Return an array of Access Control Entry (ACE) objects representing the share permissions on the share exporting this file or directory. If no DACL is present, null is returned. If the DACL is empty, an array with 0 elements is returned.

        Note that this is different from calling getSecurity on a share. There are actually two different ACLs for shares - the ACL on the share and the ACL on the folder being shared. Go to Computer Management > System Tools > Shared Folders > Shares and look at the Properties for a share. You will see two tabs - one for "Share Permissions" and another for "Security". These correspond to the ACLs returned by getShareSecurity and getSecurity respectively.

        Parameters:
        resolveSids - Attempt to resolve the SIDs within each ACE form their numeric representation to their corresponding account names.
        Throws:
        IOException
      • getSecurity

        public ACE[] getSecurity()
                          throws IOException
        Return an array of Access Control Entry (ACE) objects representing the security descriptor associated with this file or directory.

        Initially, the SIDs within each ACE will not be resolved however when getType(), getDomainName(), getAccountName(), or toString() is called, the names will attempt to be resolved. If the names cannot be resolved (e.g. due to temporary network failure), the said methods will return default values (usually S-X-Y-Z strings of fragments of).

        Alternatively getSecurity(true) may be used to resolve all SIDs together and detect network failures.

        Throws:
        IOException