c盘下建立 bak.txt文件
文件内容:
ftpuser
123456
put c:\*.bak
close
quit
执行sql语句
use master
sp_configure 'show advanced options',1
go
reconfigure
sp_configure 'xp_cmdshell',1
go
reconfigure
go
declare @tempfilename varchar(100)
set @tempfilename=CONVERT(varchar(8),getdate(),112)+convert(varchar(2),DatePart(Hour,GETDATE()))+convert(varchar(2),DataPart(Minute,GETDATE()))+convert(varchar(2),DataPart(second,GETDATE()))
declare @tempfilename1 varchar(100)
set @tempfilename1='C:\testdb'+@tempfilename+'.BAK'
backup database test to disk =@tempfilename1
EXEC xp_cmdshell 'ftp -s:c:\bak.txt 192.168.190.71'
declare @temp varchar(100)
set @temp='ren c:\testdb'+@tempfilenam+'.BAK'+'testdb'+@tempfilename+'.BAK'
EXEC xp_cmdshell @temp