求在mssql数据库执行FTP下载文件命令,高手尽量把语句写出来,谢谢了!

解决方案 »

  1.   


    --Create an instance of FTP Object
    Set NoCount on
    DECLARE @hr int --Holds error value for each sp_OA function
    DECLARE @oPKG int --Holds the handle of the object
    Declare @source varchar(255) --Hold error info
    Declare @description varchar(255)--Hold error description
    Declare @connected  int --Hold the handle of the Internet session
    declare @opened int --Hold the handle of the connection to the FTP Server
    declare @getfile bit --Result of the success(1)/Failure(2) of the getfile operation--First, we want to create the object and store it's handle in @oPKG
    EXEC @hr =  sp_OACreate 'FTP_SQLTeam.FTP_SQLDll', @oPKG OUT--Check for errors
    IF @hr <> 0
    BEGIN
        PRINT  '***  Create Package object failed'
        EXEC   sp_OAGetErrorInfo @oPKG, @source OUT, @description OUT
    select @description ,@source
        RETURN
    END--Establish our internet connection
    -- VB Equivalent=Open_Internet("myftp", 1, vbNullString, vbNullString, 0)
    Exec @hr=sp_OAMethod @oPkg,Open_Internet,@opened Out,
    @alias='myftp',
    @accesstype=1,
    @proxy='',
    @bypass='',
    @flags=0

    --Connect to the FTP Server(microsoft.com)
    --vb Equivalent Connect_Internet(connected, "ftp.microsoft.com", , __
    -- "anonymous", "[email protected]", 1, 0, 0)
    Exec @hr=sp_OAMethod @oPkg,Connect_Internet,@Connected Out,
    @handleid=@opened,
    @server='ftp.microsoft.com',
    @port=0,
    @username='anonymous',
    @pwd='[email protected]',
    @service=1,
    @flags=0,
    @context=0

    --Get the file and direct it to our local drive
    --vb Equivalent Get_File(sessionid, remotefile, newfile, _
    -- failifexists, flagsandattr, flags, context) As Boolean
    Exec @hr=sp_OAMethod @oPkg,Get_File,@getfile OUT,
    @sessionid=@Connected,
    @remotefile='/bussys/readme.txt',
    @newfile='c:\msreadme.txt',
    @failifexists=0,
    @flagsandattr=0,
    @flags=1,
    @context=0参考http://www.sqlteam.com/article/using-ftp-in-transact-sql
      

  2.   

    执行出现一些错误提示
     无效的类别字符串 ODSOLE Extended Procedure