SQL Server
SQL Server
Get an FTP Listing Entry's Permissions
See more FTP Examples
Demonstrates the Chilkat Ftp2.GetPermissions method, which returns the permissions or status string of a cached directory-listing entry. The only argument is a zero-based index. The value is empty when the server provides no such metadata.
Background: FTP has no single standard permissions format, so what this returns depends on the server — commonly a Unix-style mode string like
drwxr-xr-x, but potentially something else. Because the format varies, pair it with GetPermType to learn how to interpret the string before parsing it, rather than assuming a fixed layout.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.GetPermissions method, which returns the permissions or status string of
-- a cached directory-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
-- The permissions string is empty when the server provides no such metadata. Use
-- GetPermType to learn how to interpret the string's format.
DECLARE @perms nvarchar(4000)
EXEC sp_OAMethod @ftp, 'GetPermissions', @perms OUT, @i
PRINT @perms + ' ' + @name
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