SQL Server
SQL Server
Get a Remote File's Group
See more SFTP Examples
Demonstrates the Chilkat SFtp.GetFileGroup method, which returns a remote file's group ownership. The arguments are the remote path (or handle), whether symbolic links are followed, and whether the first argument is a handle.
Background: The group is the second half of Unix ownership, and it drives the "group" permission bits — the mechanism by which several accounts share access to the same files. As with the owner, the server may return a numeric GID when it cannot resolve a name, and the value is meaningful only on servers that implement Unix-style ownership.
Chilkat SQL Server Downloads
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
-- Demonstrates the SFtp.GetFileGroup method, which returns a remote file's group ownership. The
-- 1st argument is the remote path (or handle), the 2nd selects whether symbolic links are
-- followed, and the 3rd indicates whether the 1st argument is a handle.
DECLARE @sftp int
EXEC @hr = sp_OACreate 'Chilkat.SFtp', @sftp OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
-- Connect, authenticate, and initialize the SFTP subsystem.
DECLARE @port int
SELECT @port = 22
EXEC sp_OAMethod @sftp, 'Connect', @success OUT, 'sftp.example.com', @port
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @sftp, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @sftp
RETURN
END
-- Normally you would not hard-code the password in source. You should instead obtain it
-- from an interactive prompt, environment variable, or a secrets vault.
DECLARE @password nvarchar(4000)
SELECT @password = 'mySshPassword'
EXEC sp_OAMethod @sftp, 'AuthenticatePw', @success OUT, 'mySshLogin', @password
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @sftp, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @sftp
RETURN
END
EXEC sp_OAMethod @sftp, 'InitializeSftp', @success OUT
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @sftp, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @sftp
RETURN
END
-- The 2nd argument (bFollowLinks) selects whether a symbolic link is followed to its target.
-- The 3rd argument (bIsHandle) is 0 here because the 1st argument is a path, not an
-- open handle.
DECLARE @bFollowLinks int
SELECT @bFollowLinks = 1
DECLARE @bIsHandle int
SELECT @bIsHandle = 0
DECLARE @group nvarchar(4000)
EXEC sp_OAMethod @sftp, 'GetFileGroup', @group OUT, 'subdir/report.pdf', @bFollowLinks, @bIsHandle
EXEC sp_OAGetProperty @sftp, 'LastMethodSuccess', @iTmp0 OUT
IF @iTmp0 = 0
BEGIN
EXEC sp_OAGetProperty @sftp, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @sftp
RETURN
END
PRINT 'Group: ' + @group
EXEC sp_OAMethod @sftp, 'Disconnect', NULL
EXEC @hr = sp_OADestroy @sftp
END
GO