SQL Server
SQL Server
chmod (Setting File Permissions)
See more FTP Examples
This example assumes your FTP server supports the "chmod" command, which typically means it must be a server running on a Linux or Unix system. The SendCommand method may be called to send arbitrary commands to the FTP server. This example sends a "chmod" command to set the file permissions.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
-- Important: Do not use nvarchar(max). See the warning about using nvarchar(max).
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
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.cknotes.com'
EXEC sp_OASetProperty @ftp, 'Username', 'myLogin'
EXEC sp_OASetProperty @ftp, 'Password', 'myPassword'
-- Connect and login to the FTP server.
EXEC sp_OAMethod @ftp, 'Connect', @success OUT
IF @success <> 1
BEGIN
EXEC sp_OAGetProperty @ftp, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @ftp
RETURN
END
-- Send a chmod command to the FTP server to set
-- the permissions of a file to 0644:
DECLARE @resp nvarchar(4000)
EXEC sp_OAMethod @ftp, 'SendCommand', @resp OUT, 'chmod 0644 hamlet.xml'
EXEC sp_OAGetProperty @ftp, 'LastMethodSuccess', @iTmp0 OUT
IF @iTmp0 <> 1
BEGIN
-- Failed.
EXEC sp_OAGetProperty @ftp, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
END
ELSE
BEGIN
-- You should write code to examine the response to
-- the SendCommand. As an example, the FTP server
-- used for testing responds with this for success:
-- 200 Permissions changed on hamlet.xml
PRINT @resp
END
EXEC sp_OAMethod @ftp, 'Disconnect', @success OUT
EXEC @hr = sp_OADestroy @ftp
END
GO