SQL Server
SQL Server
Get the Format of an FTP Entry's Permissions String
See more FTP Examples
Demonstrates the Chilkat Ftp2.GetPermType method, which returns the format identifier for the permissions string of a cached listing entry. The only argument is a zero-based index. The value is empty when no permissions are available.
Background: Because different servers express permissions differently,
GetPermissions alone is ambiguous — the same characters could mean different things. GetPermType names the format so your code knows which parser to apply, or whether to treat the string as an opaque label. It is the companion you check first when permissions actually need to be interpreted rather than merely displayed.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 @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
-- Demonstrates the Ftp2.GetPermType method, which returns the format identifier for the
-- permissions string of a cached listing entry. The only argument is a zero-based index.
DECLARE @ftp int
EXEC @hr = sp_OACreate 'Chilkat.Ftp2', @ftp OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
EXEC sp_OASetProperty @ftp, 'Hostname', 'ftp.example.com'
EXEC sp_OASetProperty @ftp, 'Username', 'myFtpLogin'
-- 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.
EXEC sp_OASetProperty @ftp, 'Password', 'myPassword'
EXEC sp_OAMethod @ftp, 'Connect', @success OUT
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @ftp, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @ftp
RETURN
END
EXEC sp_OAMethod @ftp, 'ChangeRemoteDir', @success OUT, 'public_html'
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @ftp, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @ftp
RETURN
END
-- GetDirCount retrieves the directory listing on the first call and returns the number of
-- entries. A negative return indicates failure.
DECLARE @n int
EXEC sp_OAMethod @ftp, 'GetDirCount', @n OUT
IF @n < 0
BEGIN
EXEC sp_OAGetProperty @ftp, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @ftp
RETURN
END
DECLARE @i int
SELECT @i = 0
WHILE @i <= @n - 1
BEGIN
DECLARE @name nvarchar(4000)
EXEC sp_OAMethod @ftp, 'GetFilename', @name OUT, @i
-- GetPermType tells you how to interpret the GetPermissions string (for example a Unix-style
-- "drwxr-xr-x" versus another format). It is empty when no permissions are available.
DECLARE @permType nvarchar(4000)
EXEC sp_OAMethod @ftp, 'GetPermType', @permType OUT, @i
DECLARE @perms nvarchar(4000)
EXEC sp_OAMethod @ftp, 'GetPermissions', @perms OUT, @i
PRINT @name + ' perms=' + @perms + ' (' + @permType + ')'
SELECT @i = @i + 1
END
EXEC sp_OAMethod @ftp, 'Disconnect', @success OUT
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @ftp, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @ftp
RETURN
END
EXEC @hr = sp_OADestroy @ftp
END
GO