Class SmbSession
java.lang.Object
org.springframework.integration.smb.session.SmbSession
- All Implemented Interfaces:
Closeable
,AutoCloseable
,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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
append
(InputStream inputStream, String destination) Append to a file.void
close()
jcifs.smb.SmbFile
createSmbDirectoryObject
(String _path) Create an SMB file object pointing to a remote directory.jcifs.smb.SmbFile
createSmbFileObject
(String _path) Create an SMB file object pointing to a remote file.boolean
Check whether the remote resource exists.boolean
Invoke after closing the InputStream fromSession.readRaw(String)
.Get the underlying client library's client instance for this session.Return the host:port pair this session is connected to.boolean
isDirectory
(String _path) Check whether the remote resource is a directory.boolean
Check whether the remote resource is a file.boolean
isOpen()
Check whether this SMB session is open and ready for work by attempting to list remote files and checking for error conditions.jcifs.smb.SmbFile[]
Return the contents of the specified SMB resource as an array of SmbFile objects.String[]
Return the contents of the specified SMB resource as an array of SmbFile filenames.boolean
Create the specified remote path if not yet exists.void
read
(String _path, OutputStream _outputStream) Read the remote resource specified by path and copies its contents to the specifiedOutputStream
.Retrieve a remote file as a rawInputStream
.boolean
Delete the file or directory at the specified path.void
boolean
Remove a remote directory.jcifs.smb.SmbFile
Convenience method to write a byte array to a remote location.jcifs.smb.SmbFile
Convenience method to write a local file object to a remote location.void
write
(InputStream _inputStream, String _path) Write contents of the specifiedInputStream
to the remote resource specified by path.
-
Constructor Details
-
Method Details
-
remove
Delete the file or directory at the specified path.- Specified by:
remove
in interfaceSession<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
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 interfaceSession<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.
-
read
Read the remote resource specified by path and copies its contents to the specifiedOutputStream
.- Specified by:
read
in interfaceSession<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
Write contents of the specifiedInputStream
to the remote resource specified by path. Remote directories are created implicitly as required.- Specified by:
write
in interfaceSession<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
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
Convenience method to write a byte array to a remote location.- Parameters:
_contents
- thebyte[]
to write_path
- the remote file to write to- Returns:
- the
SmbFile
for remote file - Throws:
IOException
- the IO exception
-
mkdir
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 interfaceSession<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
Check whether the remote resource exists.- Specified by:
exists
in interfaceSession<jcifs.smb.SmbFile>
- Parameters:
_path
- remote path- Returns:
- true if exists, false otherwise
- Throws:
IOException
- on error conditions returned by a CIFS server
-
isFile
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
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
- Specified by:
rename
in interfaceSession<jcifs.smb.SmbFile>
- Throws:
IOException
-
append
Description copied from interface:Session
Append to a file.- Specified by:
append
in interfaceSession<jcifs.smb.SmbFile>
- Parameters:
inputStream
- the stream.destination
- the destination.- Throws:
IOException
- an IO Exception.
-
rmdir
Description copied from interface:Session
Remove a remote directory.- Specified by:
rmdir
in interfaceSession<jcifs.smb.SmbFile>
- Parameters:
directory
- The directory.- Returns:
- True if the directory was removed.
- Throws:
IOException
- an IO exception.
-
readRaw
Description copied from interface:Session
Retrieve a remote file as a rawInputStream
.- Specified by:
readRaw
in interfaceSession<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 fromSession.readRaw(String)
. Required by some session providers.- Specified by:
finalizeRaw
in interfaceSession<jcifs.smb.SmbFile>
- Returns:
- true if successful.
-
getClientInstance
Description copied from interface:Session
Get the underlying client library's client instance for this session. Returns anObject
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 interfaceSession<jcifs.smb.SmbFile>
- Returns:
- The client instance.
-
close
public void close() -
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. -
createSmbFileObject
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
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
Description copied from interface:Session
Return the host:port pair this session is connected to.- Specified by:
getHostPort
in interfaceSession<jcifs.smb.SmbFile>
- Returns:
- the host:port pair this session is connected to.
-
listNames
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 interfaceSession<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.
-