NAME

SMB::File - Remote or local file abstraction for SMB

SYNOPSIS

        use SMB::File;

        # create local file object for server
        my $file = SMB::File->new(
                name => $create_request->file_name,
                share_root => $tree->root,
                is_ipc => $tree->is_ipc,
        );
        say $file->name;      # "john\\file.txt"
        say $file->filename;  # "/my/shares/Users/john/file.txt"


        # acquire remote file object(s) for client
        my $file = $create_response->openfile->file;
        my @files = @{$querydirectory_response->files};

DESCRIPTION

This class implements an SMB file abstraction for a client or a server.

This class inherits from SMB, so msg, err, mem, dump, auto-created field accessor and other methods are available as well.

CONSTANTS

The following constants are available as SMB::File::CONSTANT_NAME.

        ATTR_READONLY
        ATTR_HIDDEN
        ATTR_SYSTEM
        ATTR_DIRECTORY
        ATTR_ARCHIVE
        ATTR_DEVICE
        ATTR_NORMAL
        ATTR_TEMPORARY
        ATTR_SPARSE_FILE
        ATTR_REPARSE_POINT
        ATTR_COMPRESSED
        ATTR_OFFLINE
        ATTR_NOT_CONTENT_INDEXED
        ATTR_ENCRYPTED

        DISPOSITION_SUPERSEDE
        DISPOSITION_OPEN
        DISPOSITION_CREATE
        DISPOSITION_OPEN_IF
        DISPOSITION_OVERWRITE
        DISPOSITION_OVERWRITE_IF

        ACTION_NONE
        ACTION_SUPERSEDED
        ACTION_OPENED
        ACTION_CREATED
        ACTION_OVERWRITTEN

METHODS

new [OPTIONS]

Class constructor. Creates an instance of SMB::File.

The following keys of OPTIONS hash are recognized in addition to the ones recognized by superclass SMB:

        name          SMB name, no need to start with a backslash
        is_directory  for remote file, this is an attribute hint
        share_root    for local file, this is the share directory
        is_ipc        for local or remote file in IPC tree
update CREATION_TIME LAST_ACCESS_TIME LAST_WRITE_TIME CHANGE_TIME ALLOCATION_SIZE END_OF_FILE ATTRIBUTES [SWAPPED=0]

Updates corresponding file times (each uint64), sizes (each uint64) and attributes (uint32). Flag SWAPPED indicates that the sizes are swapped (first end_of_file, then allocation_size).

is_directory

Returns true when the file is marked or stat'd as a directory.

ctime

Returns file creation_time as unix time.

atime

Returns file last_access_time as unix time.

wtime

Returns file last_write_time as unix time.

mtime

Returns file change_time as unix time.

ctime_string [FORMAT]

Returns file creation_time as string using function time_to_string.

atime_string [FORMAT]

Returns file last_access_time as string using function time_to_string.

wtime_string [FORMAT]

Returns file last_write_time as string using function time_to_string.

mtime_string [FORMAT]

Returns file change_time as string using function time_to_string.

size

Returns file size in bytes. This is just an alias to end_of_file.

size_string

Returns file size in human readable form that is always not longer than 9 characters, like: "314159265", "34.567 G", "234.567 T" or "785634e12".

add_openfile HANDLE ACTION

Create and return an SMB::OpenFile object using supplied HANDLE and ACTION, intended for local files on server side. HANDLE may be undef for special open files (like IPC files srvsvc and wkssvc). Increments the number of open files for this file object.

delete_openfile OPENFILE

The opposite of add_openfile, closes handle if needed and decrements the number of open files for this file object.

supersede
open
create
overwrite
open_if
overwrite_if
open_by_disposition DISPOSITION

Opens local file by given disposition (using NTFS / SMB semantics). Returns an SMB::OpenFile object on success or undef on failure. The openfile object is created by calling add_openfile internally.

find_files PARAMS

Returns an array ref of SMB::File objects corresponding to the files in this local file object that is a directory. PARAMS is a hash with optional keys "pattern" (default "*") and "start_idx" (default 0).

FUNCTIONS

None of the following functions are exported. But they may be called as SMB::File::FUNC_NAME.

from_ntattr NTFS_ATTR

Converts from NTFS attributes (uint32) to Unix mode (unsigned int).

to_ntattr UNIX_MODE

Converts from Unix mode (unsigned int) to NTFS attributes (uint32).

time_to_string TIME [FORMAT="%4Y-%2m-%2d %2H:%2M"]

Returns human readable representation of unix time (uint32).

SEE ALSO

SMB::OpenFile, SMB::Tree, SMB::Client, SMB::Server, SMB.

AUTHOR

Mikhael Goikhman <migo@cpan.org>