C# Class SharpCifs.Smb.SmbFile

This class represents a resource on an SMB network.
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 Sharpen.FilePath 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:
 smb://[[[domain;]username[:password]@]server[:port]/[[share/[dir/]file]]][?[param=value[param2=value2[...]]] 
This example:
 smb://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 'smb://' URLs it is necessary to first call the static jcifs.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 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
smb://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.
smb://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.
smb://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.
smb://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.
smb:// Just as smb://server/ lists shares and smb://workgroup/ lists servers, the smb:// 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).
smb://angus.foo.net/d/jcifs/pipes.doc The server name may also be a DNS name as it is in this example. See Setting Name Resolution Properties for details.
smb://192.168.1.15/ADMIN$/ The server name may also be an IP address. See <a href="../../../resolver.html">Setting Name Resolution Properties for details.
smb://domain;username:password@server/share/path/to/file.txt A prototypical example that uses all the fields.
smb://myworkgroup/angus/ <-- ILLEGAL Despite the hierarchial relationship between workgroups, servers, and filesystems this example is not valid.
smb://server/share/path/to/dir <-- ILLEGAL URLs that represent workgroups, servers, shares, or directories require a trailing slash '/'.
smb://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
smb://host/share/a/b/ c/d/ smb://host/share/a/b/c/d/
smb://host/share/foo/bar/ /share2/zig/zag smb://host/share2/zig/zag
smb://host/share/foo/bar/ ../zip/ smb://host/share/foo/zip/
smb://host/share/zig/zag smb://foo/bar/ smb://foo/bar/
smb://host/share/foo/ ../.././.././../foo/ smb://host/foo/
smb://host/share/zig/zag / smb://host/
smb://server/ ../ smb://server/
smb:// myworkgroup/ smb://myworkgroup/
smb://myworkgroup/ angus/ smb://myworkgroup/angus/ <-- ILLEGAL
(But if you first create an SmbFile with 'smb://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.

Inheritance: SharpCifs.Util.Sharpen.UrlConnection
Mostra file Open project: brandonprry/Potato Class Usage Examples

Protected Properties

Property Type Description
Dfs Dfs

Public Methods

Method Description
CanRead ( ) : bool

Tests to see if the file this SmbFile represents can be read.

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.

CanWrite ( ) : bool

Tests to see if the file this SmbFile represents exists and is not marked read-only.

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 smb://, smb://workgroup/, and smb://server/ resources will be read-only.

Connect ( ) : void

It is not necessary to call this method directly.

It is not necessary to call this method directly. This is the URLConnection implementation of connect().

CopyTo ( SmbFile dest ) : void

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 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.

CreateNewFile ( ) : void

Create a new file but fail if it already exists.

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.

CreateTime ( ) : long

Retrieve the time this SmbFile was created.

Retrieve the time this SmbFile was created. The value returned is suitable for constructing a System.DateTime 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.

Delete ( ) : void

This method will delete the file or directory specified by this SmbFile.

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.

Equals ( object obj ) : bool

Tests to see if two SmbFile objects are equal.

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.

 smb://192.168.1.15/share/DIR/foo.txt smb://angus/share/data/../dir/foo.txt 
Exists ( ) : bool

Tests to see if the SMB resource exists.

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 smb:// 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.

GetAttributes ( ) : int

Return the attributes of this file.

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.

GetCanonicalPath ( ) : string

Returns the full URL of this SMB resource with '.' and '..' components factored out.

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.

GetContentLength ( ) : int

This URLConnection method just returns the result of length().

This URLConnection method just returns the result of length().

GetDate ( ) : long

This URLConnection method just returns the result of lastModified.

This URLConnection method just returns the result of lastModified.

GetDfsPath ( ) : string

If the path of this SmbFile falls within a DFS volume, this method will return the referral path to which it maps.

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.

GetDiskFreeSpace ( ) : long

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.

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.

GetHashCode ( ) : int

Computes a hashCode for this file based on the URL string and IP address if the server.

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.

GetInputStream ( ) : InputStream

This URLConnection method just returns a new SmbFileInputStream created with this file.

This URLConnection method just returns a new SmbFileInputStream created with this file.

GetLastModified ( ) : long

This URLConnection method just returns the result of lastModified.

This URLConnection method just returns the result of lastModified.

GetName ( ) : string

Returns the last component of the target URL.

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 smb:// is also smb://. 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.

GetOutputStream ( ) : OutputStream

This URLConnection method just returns a new SmbFileOutputStream created with this file.

This URLConnection method just returns a new SmbFileOutputStream created with this file.

GetParent ( ) : string

Everything but the last component of the URL representing this SMB resource is effectivly it's parent.

Everything but the last component of the URL representing this SMB resource is effectivly it's parent. The root URL smb:// does not have a parent. In this case smb:// is returned.

GetPath ( ) : string

Returns the full uncanonicalized URL of this SMB resource.

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.

GetPrincipal ( ) : Principal

Returns the NtlmPasswordAuthentication object used as credentials with this file or pipe.

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).

GetSecurity ( ) : Ace[]

Return an array of Access Control Entry (ACE) objects representing the security descriptor associated with this file or directory.

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.

GetSecurity ( bool resolveSids ) : Ace[]

Return an array of Access Control Entry (ACE) objects representing the security descriptor associated with this file or directory.

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.

GetServer ( ) : string

Retrieve the hostname of the server for this SMB resource.

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.

GetShare ( ) : string

Retrieves the share associated with this SMB resource.

Retrieves the share associated with this SMB resource. In the case of smb://, smb://workgroup/, and smb://server/ URLs which do not specify a share, null will be returned.

GetShareSecurity ( bool resolveSids ) : Ace[]

Return an array of Access Control Entry (ACE) objects representing the share permissions on the share exporting this file or directory.

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.

GetType ( ) : int

Returns type of of object this SmbFile represents.

Returns type of of object this SmbFile represents.

GetUncPath ( ) : string

Retuns the Windows UNC style path with backslashs intead of forward slashes.

Retuns the Windows UNC style path with backslashs intead of forward slashes.

IsDirectory ( ) : bool

Tests to see if the file this SmbFile represents is a directory.

Tests to see if the file this SmbFile represents is a directory.

IsFile ( ) : bool

Tests to see if the file this SmbFile represents is not a directory.

Tests to see if the file this SmbFile represents is not a directory.

IsHidden ( ) : bool

Tests to see if the file this SmbFile represents is marked as hidden.

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$.

LastModified ( ) : long

Retrieve the last time the file represented by this SmbFile was modified.

Retrieve the last time the file represented by this SmbFile was modified. The value returned is suitable for constructing a System.DateTime object (i.e. seconds since Epoch 1970). Times should be the same as those reported using the properties dialog of the Windows Explorer program.

Length ( ) : long

Returns the length of this SmbFile in bytes.

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.

List ( ) : string[]

List the contents of this SMB resource.

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 smb://,
  • all servers registered as members of a NetBIOS workgroup if this resource refers to a workgroup in a smb://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 smb://server/,
  • or null if the resource cannot be resolved.
List ( ISmbFilenameFilter filter ) : string[]

List the contents of this SMB resource.

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.

ListFiles ( ) : SmbFile[]

List the contents of this SMB resource as an array of SmbFile objects.

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 smb://,
  • all servers registered as members of a NetBIOS workgroup if this resource refers to a workgroup in a smb://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 smb://server/,
  • or null if the resource cannot be resolved.
ListFiles ( ISmbFileFilter filter ) : SmbFile[]

List the contents of this SMB resource.

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.

ListFiles ( ISmbFilenameFilter filter ) : SmbFile[]

List the contents of this SMB resource.

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.

ListFiles ( string wildcard ) : SmbFile[]

The CIFS protocol provides for DOS "wildcards" to be used as a performance enhancement.

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 
Mkdir ( ) : void

Creates a directory with the path specified by this SmbFile.

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 smb://, smb://workgroup/, smb://server/, or smb://server/share/ URLs because workgroups, servers, and shares cannot be dynamically created (although in the future it may be possible to create shares).

Mkdirs ( ) : void

Creates a directory with the path specified by this SmbFile and any parent directories that do not exist.

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 smb://, smb://workgroup/, smb://server/, or smb://server/share/ URLs because workgroups, servers, and shares cannot be dynamically created (although in the future it may be possible to create shares).

RenameTo ( SmbFile dest ) : void

Changes the name of the file this SmbFile represents to the name designated by the SmbFile argument.

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.

SetAttributes ( int attrs ) : void

Set the attributes of this file.

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.

SetCreateTime ( long time ) : void

Set the create time of the file.

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.

SetLastModified ( long time ) : void

Set the last modified time of the file.

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.

SetReadOnly ( ) : void

Make this file read-only.

Make this file read-only. This is shorthand for setAttributes( getAttributes() | ATTR_READ_ONLY ).

SetReadWrite ( ) : void

Turn off the read-only attribute of this file.

Turn off the read-only attribute of this file. This is shorthand for setAttributes( getAttributes() & ~ATTR_READONLY ).

SmbFile ( SmbFile context, string name ) : System

Constructs an SmbFile representing a resource on an SMB network such as a file or directory.

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.

SmbFile ( SmbFile context, string name, int shareAccess ) : System

Constructs an SmbFile representing a resource on an SMB network such as a file or directory.

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.

SmbFile ( Uri url, NtlmPasswordAuthentication auth ) : System

Constructs an SmbFile representing a resource on an SMB network such as a file or directory from a URL object and an NtlmPasswordAuthentication object.

Constructs an SmbFile representing a resource on an SMB network such as a file or directory from a URL object and an NtlmPasswordAuthentication object.

SmbFile ( string url ) : System

Constructs an SmbFile representing a resource on an SMB network such as a file or directory.

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.

SmbFile ( string url, NtlmPasswordAuthentication auth ) : System

Constructs an SmbFile representing a resource on an SMB network such as a file or directory.

Constructs an SmbFile representing a resource on an SMB network such as a file or directory.

SmbFile ( string url, NtlmPasswordAuthentication auth, int shareAccess ) : System

Constructs an SmbFile representing a file on an SMB network.

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.

SmbFile ( string context, string name ) : System

Constructs an SmbFile representing a resource on an SMB network such as a file or directory.

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.

SmbFile ( string context, string name, NtlmPasswordAuthentication auth ) : System

Constructs an SmbFile representing a resource on an SMB network such as a file or directory.

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.

SmbFile ( string context, string name, NtlmPasswordAuthentication auth, int shareAccess ) : System

Constructs an SmbFile representing a resource on an SMB network such as a file or directory.

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.

ToString ( ) : string

Returns the string representation of this SmbFile object.

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.

Protected Methods

Method Description
PathNamesPossiblyEqual ( string path1, string path2 ) : bool
SmbFile ( Uri url ) : System

Constructs an SmbFile representing a resource on an SMB network such as a file or directory from a URL object.

Constructs an SmbFile representing a resource on an SMB network such as a file or directory from a URL object.

Private Methods

Method Description
Blank_resp ( ) : SmbComBlankResponse
Close ( ) : void
Close ( int f, long lastWriteTime ) : void
Close ( long lastWriteTime ) : void
Connect0 ( ) : void
CopyTo0 ( SmbFile dest, byte b, int bsize, WriterThread w, SmbComReadAndX req, SmbComReadAndXResponse resp ) : void
Delete ( string fileName ) : void
DoConnect ( ) : void
DoDfsRootEnum ( ) : IFileEntry[]
DoEnum ( List list, bool files, string wildcard, int searchAttributes, ISmbFilenameFilter fnf, ISmbFileFilter ff ) : void
DoFindFirstNext ( List list, bool files, string wildcard, int searchAttributes, ISmbFilenameFilter fnf, ISmbFileFilter ff ) : void
DoMsrpcShareEnum ( ) : IFileEntry[]
DoNetServerEnum ( List list, bool files, string wildcard, int searchAttributes, ISmbFilenameFilter fnf, ISmbFileFilter ff ) : void
DoNetShareEnum ( ) : IFileEntry[]
DoShareEnum ( List list, bool files, string wildcard, int searchAttributes, ISmbFilenameFilter fnf, ISmbFileFilter ff ) : void
GetAddress ( ) : UniAddress
GetFirstAddress ( ) : UniAddress
GetNextAddress ( ) : UniAddress
GetServerWithDfs ( ) : string
GetUncPath0 ( ) : string
HasNextAddress ( ) : bool
IsConnected ( ) : bool
IsOpen ( ) : bool
IsWorkgroup0 ( ) : bool
List ( string wildcard, int searchAttributes, ISmbFilenameFilter fnf, ISmbFileFilter ff ) : string[]
ListFiles ( string wildcard, int searchAttributes, ISmbFilenameFilter fnf, ISmbFileFilter ff ) : SmbFile[]
Open ( int flags, int access, int attrs, int options ) : void
Open0 ( int flags, int access, int attrs, int options ) : int
ProcessAces ( Ace aces, bool resolveSids ) : void
QueryFsInformation ( int level ) : long
QueryLookup ( string query, string param ) : string
QueryPath ( string path, int infoLevel ) : IInfo
RemoveCurrentAddress ( ) : void
ResolveDfs ( ServerMessageBlock request ) : void
Send ( ServerMessageBlock request, ServerMessageBlock response ) : void
SetPathInformation ( int attrs, long ctime, long mtime ) : void
SmbFile ( ) : System
SmbFile ( SmbFile context, string name, int type, int attributes, long createTime, long lastModified, long size ) : System
ToUrl ( ) : Uri

Method Details

CanRead() public method

Tests to see if the file this SmbFile represents can be read.
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.
public CanRead ( ) : bool
return bool

CanWrite() public method

Tests to see if the file this SmbFile represents exists and is not marked read-only.
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 smb://, smb://workgroup/, and smb://server/ resources will be read-only.
public CanWrite ( ) : bool
return bool

Connect() public method

It is not necessary to call this method directly.
It is not necessary to call this method directly. This is the URLConnection implementation of connect().
public Connect ( ) : void
return void

CopyTo() public method

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 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.

SmbException
public CopyTo ( SmbFile dest ) : void
dest SmbFile the destination file or directory
return void

CreateNewFile() public method

Create a new file but fail if it already exists.
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.
public CreateNewFile ( ) : void
return void

CreateTime() public method

Retrieve the time this SmbFile was created.
Retrieve the time this SmbFile was created. The value returned is suitable for constructing a System.DateTime 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.
public CreateTime ( ) : long
return long

Delete() public method

This method will delete the file or directory specified by this SmbFile.
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.
SmbException
public Delete ( ) : void
return void

Equals() public method

Tests to see if two SmbFile objects are equal.
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.

 smb://192.168.1.15/share/DIR/foo.txt smb://angus/share/data/../dir/foo.txt 
SmbException
public Equals ( object obj ) : bool
obj object Another SmbFile object to compare for equality
return bool

Exists() public method

Tests to see if the SMB resource exists.
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 smb:// 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.
public Exists ( ) : bool
return bool

GetAttributes() public method

Return the attributes of this file.
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.
SmbException
public GetAttributes ( ) : int
return int

GetCanonicalPath() public method

Returns the full URL of this SMB resource with '.' and '..' components factored out.
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.
public GetCanonicalPath ( ) : string
return string

GetContentLength() public method

This URLConnection method just returns the result of length().
This URLConnection method just returns the result of length().
public GetContentLength ( ) : int
return int

GetDate() public method

This URLConnection method just returns the result of lastModified.
This URLConnection method just returns the result of lastModified.
public GetDate ( ) : long
return long

GetDfsPath() public method

If the path of this SmbFile falls within a DFS volume, this method will return the referral path to which it maps.
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.
public GetDfsPath ( ) : string
return string

GetDiskFreeSpace() public method

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.
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.
public GetDiskFreeSpace ( ) : long
return long

GetHashCode() public method

Computes a hashCode for this file based on the URL string and IP address if the server.
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.
SmbException
public GetHashCode ( ) : int
return int

GetInputStream() public method

This URLConnection method just returns a new SmbFileInputStream created with this file.
This URLConnection method just returns a new SmbFileInputStream created with this file.
thrown by SmbFileInputStream constructor ///
public GetInputStream ( ) : InputStream
return InputStream

GetLastModified() public method

This URLConnection method just returns the result of lastModified.
This URLConnection method just returns the result of lastModified.
public GetLastModified ( ) : long
return long

GetName() public method

Returns the last component of the target URL.
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 smb:// is also smb://. 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.
public GetName ( ) : string
return string

GetOutputStream() public method

This URLConnection method just returns a new SmbFileOutputStream created with this file.
This URLConnection method just returns a new SmbFileOutputStream created with this file.
thrown by SmbFileOutputStream constructor ///
public GetOutputStream ( ) : OutputStream
return OutputStream

GetParent() public method

Everything but the last component of the URL representing this SMB resource is effectivly it's parent.
Everything but the last component of the URL representing this SMB resource is effectivly it's parent. The root URL smb:// does not have a parent. In this case smb:// is returned.
public GetParent ( ) : string
return string

GetPath() public method

Returns the full uncanonicalized URL of this SMB resource.
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.
public GetPath ( ) : string
return string

GetPrincipal() public method

Returns the NtlmPasswordAuthentication object used as credentials with this file or pipe.
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).
public GetPrincipal ( ) : Principal
return Principal

GetSecurity() public method

Return an array of Access Control Entry (ACE) objects representing the security descriptor associated with this file or directory.
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.

public GetSecurity ( ) : Ace[]
return Ace[]

GetSecurity() public method

Return an array of Access Control Entry (ACE) objects representing the security descriptor associated with this file or directory.
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.
public GetSecurity ( bool resolveSids ) : Ace[]
resolveSids bool /// Attempt to resolve the SIDs within each ACE form /// their numeric representation to their corresponding account names. ///
return Ace[]

GetServer() public method

Retrieve the hostname of the server for this SMB resource.
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.
public GetServer ( ) : string
return string

GetShare() public method

Retrieves the share associated with this SMB resource.
Retrieves the share associated with this SMB resource. In the case of smb://, smb://workgroup/, and smb://server/ URLs which do not specify a share, null will be returned.
public GetShare ( ) : string
return string

GetShareSecurity() public method

Return an array of Access Control Entry (ACE) objects representing the share permissions on the share exporting this file or directory.
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.

public GetShareSecurity ( bool resolveSids ) : Ace[]
resolveSids bool /// Attempt to resolve the SIDs within each ACE form /// their numeric representation to their corresponding account names. ///
return Ace[]

GetType() public method

Returns type of of object this SmbFile represents.
Returns type of of object this SmbFile represents.
public GetType ( ) : int
return int

GetUncPath() public method

Retuns the Windows UNC style path with backslashs intead of forward slashes.
Retuns the Windows UNC style path with backslashs intead of forward slashes.
public GetUncPath ( ) : string
return string

IsDirectory() public method

Tests to see if the file this SmbFile represents is a directory.
Tests to see if the file this SmbFile represents is a directory.
public IsDirectory ( ) : bool
return bool

IsFile() public method

Tests to see if the file this SmbFile represents is not a directory.
Tests to see if the file this SmbFile represents is not a directory.
public IsFile ( ) : bool
return bool

IsHidden() public method

Tests to see if the file this SmbFile represents is marked as hidden.
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$.
public IsHidden ( ) : bool
return bool

LastModified() public method

Retrieve the last time the file represented by this SmbFile was modified.
Retrieve the last time the file represented by this SmbFile was modified. The value returned is suitable for constructing a System.DateTime object (i.e. seconds since Epoch 1970). Times should be the same as those reported using the properties dialog of the Windows Explorer program.
public LastModified ( ) : long
return long

Length() public method

Returns the length of this SmbFile in bytes.
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.
SmbException
public Length ( ) : long
return long

List() public method

List the contents of this SMB resource.
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 smb://,
  • all servers registered as members of a NetBIOS workgroup if this resource refers to a workgroup in a smb://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 smb://server/,
  • or null if the resource cannot be resolved.
public List ( ) : string[]
return string[]

List() public method

List the contents of this SMB resource.
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.
# @return An array of filenames
public List ( ISmbFilenameFilter filter ) : string[]
filter ISmbFilenameFilter a filename filter to exclude filenames from the results
return string[]

ListFiles() public method

List the contents of this SMB resource as an array of SmbFile objects.
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 smb://,
  • all servers registered as members of a NetBIOS workgroup if this resource refers to a workgroup in a smb://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 smb://server/,
  • or null if the resource cannot be resolved.
public ListFiles ( ) : SmbFile[]
return SmbFile[]

ListFiles() public method

List the contents of this SMB resource.
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.
public ListFiles ( ISmbFileFilter filter ) : SmbFile[]
filter ISmbFileFilter a file filter to exclude files from the results
return SmbFile[]

ListFiles() public method

List the contents of this SMB resource.
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.
SmbException
public ListFiles ( ISmbFilenameFilter filter ) : SmbFile[]
filter ISmbFilenameFilter a filter to exclude files from the results
return SmbFile[]

ListFiles() public method

The CIFS protocol provides for DOS "wildcards" to be used as a performance enhancement.
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 
SmbException
public ListFiles ( string wildcard ) : SmbFile[]
wildcard string a wildcard expression
return SmbFile[]

Mkdir() public method

Creates a directory with the path specified by this SmbFile.
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 smb://, smb://workgroup/, smb://server/, or smb://server/share/ URLs because workgroups, servers, and shares cannot be dynamically created (although in the future it may be possible to create shares).
SmbException
public Mkdir ( ) : void
return void

Mkdirs() public method

Creates a directory with the path specified by this SmbFile and any parent directories that do not exist.
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 smb://, smb://workgroup/, smb://server/, or smb://server/share/ URLs because workgroups, servers, and shares cannot be dynamically created (although in the future it may be possible to create shares).
SmbException
public Mkdirs ( ) : void
return void

PathNamesPossiblyEqual() protected method

protected PathNamesPossiblyEqual ( string path1, string path2 ) : bool
path1 string
path2 string
return bool

RenameTo() public method

Changes the name of the file this SmbFile represents to the name designated by the SmbFile argument.
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.

If the dest argument is null ///
public RenameTo ( SmbFile dest ) : void
dest SmbFile An SmbFile that represents the new pathname
return void

SetAttributes() public method

Set the attributes of this file.
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.
SmbException
public SetAttributes ( int attrs ) : void
attrs int
return void

SetCreateTime() public method

Set the create time of the file.
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.

public SetCreateTime ( long time ) : void
time long the create time as milliseconds since Jan 1, 1970
return void

SetLastModified() public method

Set the last modified time of the file.
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.

public SetLastModified ( long time ) : void
time long the last modified time as milliseconds since Jan 1, 1970
return void

SetReadOnly() public method

Make this file read-only.
Make this file read-only. This is shorthand for setAttributes( getAttributes() | ATTR_READ_ONLY ).
SmbException
public SetReadOnly ( ) : void
return void

SetReadWrite() public method

Turn off the read-only attribute of this file.
Turn off the read-only attribute of this file. This is shorthand for setAttributes( getAttributes() & ~ATTR_READONLY ).
SmbException
public SetReadWrite ( ) : void
return void

SmbFile() public method

Constructs an SmbFile representing a resource on an SMB network such as a file or directory.
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.
/// If the parent and child parameters /// do not follow the prescribed syntax /// If the server or workgroup of the context file cannot be determined ///
public SmbFile ( SmbFile context, string name ) : System
context SmbFile A base SmbFile
name string A path string relative to the parent paremeter
return System

SmbFile() public method

Constructs an SmbFile representing a resource on an SMB network such as a file or directory.
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.
/// If the context and name parameters /// do not follow the prescribed syntax ///
public SmbFile ( SmbFile context, string name, int shareAccess ) : System
context SmbFile A base SmbFile
name string A path string relative to the context file path
shareAccess int Specifies what access other clients have while this file is open. ///
return System

SmbFile() protected method

Constructs an SmbFile representing a resource on an SMB network such as a file or directory from a URL object.
Constructs an SmbFile representing a resource on an SMB network such as a file or directory from a URL object.
protected SmbFile ( Uri url ) : System
url Uri The URL of the target resource
return System

SmbFile() public method

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

SmbFile() public method

Constructs an SmbFile representing a resource on an SMB network such as a file or directory.
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.
/// If the parent and child parameters /// do not follow the prescribed syntax ///
public SmbFile ( string url ) : System
url string A URL string
return System

SmbFile() public method

Constructs an SmbFile representing a resource on an SMB network such as a file or directory.
Constructs an SmbFile representing a resource on an SMB network such as a file or directory.
If the url parameter does not follow the prescribed syntax ///
public SmbFile ( string url, NtlmPasswordAuthentication auth ) : System
url string A URL string
auth NtlmPasswordAuthentication The credentials the client should use for authentication
return System

SmbFile() public method

Constructs an SmbFile representing a file on an SMB network.
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.
If the url parameter does not follow the prescribed syntax ///
public SmbFile ( string url, NtlmPasswordAuthentication auth, int shareAccess ) : System
url string A URL string
auth NtlmPasswordAuthentication The credentials the client should use for authentication
shareAccess int Specifies what access other clients have while this file is open. ///
return System

SmbFile() public method

Constructs an SmbFile representing a resource on an SMB network such as a file or directory.
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.
/// If the context and name parameters /// do not follow the prescribed syntax ///
public SmbFile ( string context, string name ) : System
context string A URL string
name string A path string relative to the context paremeter
return System

SmbFile() public method

Constructs an SmbFile representing a resource on an SMB network such as a file or directory.
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.
/// If the context and name parameters /// do not follow the prescribed syntax ///
public SmbFile ( string context, string name, NtlmPasswordAuthentication auth ) : System
context string A URL string
name string A path string relative to the context paremeter
auth NtlmPasswordAuthentication The credentials the client should use for authentication
return System

SmbFile() public method

Constructs an SmbFile representing a resource on an SMB network such as a file or directory.
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.
/// If the context and name parameters /// do not follow the prescribed syntax ///
public SmbFile ( string context, string name, NtlmPasswordAuthentication auth, int shareAccess ) : System
context string A URL string
name string A path string relative to the context paremeter
auth NtlmPasswordAuthentication The credentials the client should use for authentication
shareAccess int Specifies what access other clients have while this file is open. ///
return System

ToString() public method

Returns the string representation of this SmbFile object.
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.
SmbException
public ToString ( ) : string
return string

Property Details

Dfs protected_oe static_oe property

protected static Dfs Dfs
return Dfs