java.lang.Object
org.springframework.integration.smb.session.SmbSession
All Implemented Interfaces:
Closeable, AutoCloseable, Session<jcifs.smb.SmbFile>

public class SmbSession extends Object implements Session<jcifs.smb.SmbFile>
Implementation of the Session interface for Server Message Block (SMB) also known as Common Internet File System (CIFS). The Samba project set out to create non-Windows implementations of SMB. Often Samba is thus used synonymously to SMB. SMB is an application-layer network protocol that manages shared access to files, printers and other networked resources. See Server Message Block for more details.
Since:
6.0
Author:
Markus Spann, Mark Fisher, Oleg Zhurakousky, Artem Bilan, Prafull Kumar Soni, Gregory Bragg, Adam Jones
  • Constructor Details

    • SmbSession

      public SmbSession(SmbShare _smbShare)
      Constructor for an SMB session.
      Parameters:
      _smbShare - SMB share resource
  • Method Details

    • remove

      public boolean remove(String _path) throws IOException
      Delete the file or directory at the specified path.
      Specified by:
      remove in interface Session<jcifs.smb.SmbFile>
      Parameters:
      _path - path to a remote file or directory
      Returns:
      true if delete successful, false if resource is non-existent
      Throws:
      IOException - on error conditions returned by a CIFS server
    • list

      public jcifs.smb.SmbFile[] list(String _path) throws IOException
      Return the contents of the specified SMB resource as an array of SmbFile objects. In case the remote resource does not exist, an empty array is returned.
      Specified by:
      list in interface Session<jcifs.smb.SmbFile>
      Parameters:
      _path - path to a remote directory
      Returns:
      array of SmbFile objects
      Throws:
      IOException - on error conditions returned by a CIFS server or if the remote resource is not a directory.
    • listNames

      public String[] listNames(String _path) throws IOException
      Return the contents of the specified SMB resource as an array of SmbFile filenames. In case the remote resource does not exist, an empty array is returned.
      Specified by:
      listNames in interface Session<jcifs.smb.SmbFile>
      Parameters:
      _path - path to a remote directory
      Returns:
      array of SmbFile filenames
      Throws:
      IOException - on error conditions returned by a CIFS server or if the remote resource is not a directory.
    • read

      public void read(String _path, OutputStream _outputStream) throws IOException
      Read the remote resource specified by path and copies its contents to the specified OutputStream.
      Specified by:
      read in interface Session<jcifs.smb.SmbFile>
      Parameters:
      _path - path to a remote file
      _outputStream - output stream
      Throws:
      IOException - on error conditions returned by a CIFS server or if the remote resource is not a file.
    • write

      public void write(InputStream _inputStream, String _path) throws IOException
      Write contents of the specified InputStream to the remote resource specified by path. Remote directories are created implicitly as required.
      Specified by:
      write in interface Session<jcifs.smb.SmbFile>
      Parameters:
      _inputStream - input stream
      _path - remote path (of a file) to write to
      Throws:
      IOException - on error conditions returned by a CIFS server
    • write

      public jcifs.smb.SmbFile write(File _file, String _path) throws IOException
      Convenience method to write a local file object to a remote location.
      Parameters:
      _file - the local file
      _path - the remote path to write to
      Returns:
      the SmbFile for remote file
      Throws:
      IOException - the IO exception
    • write

      public jcifs.smb.SmbFile write(byte[] _contents, String _path) throws IOException
      Convenience method to write a byte array to a remote location.
      Parameters:
      _contents - the byte[] to write
      _path - the remote file to write to
      Returns:
      the SmbFile for remote file
      Throws:
      IOException - the IO exception
    • mkdir

      public boolean mkdir(String _path) throws IOException
      Create the specified remote path if not yet exists. If the specified resource is a file rather than a path, creates all directories leading to that file.
      Specified by:
      mkdir in interface Session<jcifs.smb.SmbFile>
      Parameters:
      _path - remote path to create
      Returns:
      always true (error states are express by exceptions)
      Throws:
      IOException - on error conditions returned by a CIFS server
    • exists

      public boolean exists(String _path) throws IOException
      Check whether the remote resource exists.
      Specified by:
      exists in interface Session<jcifs.smb.SmbFile>
      Parameters:
      _path - remote path
      Returns:
      true if exists, false otherwise
      Throws:
      IOException - on error conditions returned by a CIFS server
    • isFile

      public boolean isFile(String _path) throws IOException
      Check whether the remote resource is a file.
      Parameters:
      _path - remote path
      Returns:
      true if resource is a file, false otherwise
      Throws:
      IOException - on error conditions returned by a CIFS server
    • isDirectory

      public boolean isDirectory(String _path) throws IOException
      Check whether the remote resource is a directory.
      Parameters:
      _path - remote path
      Returns:
      true if resource is a directory, false otherwise
      Throws:
      IOException - on error conditions returned by a CIFS server
    • rename

      public void rename(String _pathFrom, String _pathTo) throws IOException
      Specified by:
      rename in interface Session<jcifs.smb.SmbFile>
      Throws:
      IOException
    • append

      public void append(InputStream inputStream, String destination) throws IOException
      Description copied from interface: Session
      Append to a file.
      Specified by:
      append in interface Session<jcifs.smb.SmbFile>
      Parameters:
      inputStream - the stream.
      destination - the destination.
      Throws:
      IOException - an IO Exception.
    • rmdir

      public boolean rmdir(String directory) throws IOException
      Description copied from interface: Session
      Remove a remote directory.
      Specified by:
      rmdir in interface Session<jcifs.smb.SmbFile>
      Parameters:
      directory - The directory.
      Returns:
      True if the directory was removed.
      Throws:
      IOException - an IO exception.
    • readRaw

      public InputStream readRaw(String source) throws IOException
      Description copied from interface: Session
      Retrieve a remote file as a raw InputStream.
      Specified by:
      readRaw in interface Session<jcifs.smb.SmbFile>
      Parameters:
      source - The path of the remote file.
      Returns:
      The raw inputStream.
      Throws:
      IOException - Any IOException.
    • finalizeRaw

      public boolean finalizeRaw()
      Description copied from interface: Session
      Invoke after closing the InputStream from Session.readRaw(String). Required by some session providers.
      Specified by:
      finalizeRaw in interface Session<jcifs.smb.SmbFile>
      Returns:
      true if successful.
    • getClientInstance

      public Object getClientInstance()
      Description copied from interface: Session
      Get the underlying client library's client instance for this session. Returns an Object to avoid significant changes to -file, -ftp, -sftp modules, which would be required if we added another generic parameter. Implementations should narrow the return type.
      Specified by:
      getClientInstance in interface Session<jcifs.smb.SmbFile>
      Returns:
      The client instance.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface Session<jcifs.smb.SmbFile>
    • isOpen

      public boolean isOpen()
      Check whether this SMB session is open and ready for work by attempting to list remote files and checking for error conditions.
      Specified by:
      isOpen in interface Session<jcifs.smb.SmbFile>
      Returns:
      true if the session is open, false otherwise
    • createSmbFileObject

      public jcifs.smb.SmbFile createSmbFileObject(String _path) throws IOException
      Create an SMB file object pointing to a remote file.
      Parameters:
      _path - the remote file path
      Returns:
      the SmbFile for remote path
      Throws:
      IOException - the IO exception
    • createSmbDirectoryObject

      public jcifs.smb.SmbFile createSmbDirectoryObject(String _path) throws IOException
      Create an SMB file object pointing to a remote directory.
      Parameters:
      _path - the remote directory path
      Returns:
      the SmbFile for remote path
      Throws:
      IOException - the IO exception
    • getHostPort

      public String getHostPort()
      Description copied from interface: Session
      Return the host:port pair this session is connected to.
      Specified by:
      getHostPort in interface Session<jcifs.smb.SmbFile>
      Returns:
      the host:port pair this session is connected to.