我正在使用下面的代码片段将简单的文本文件从 Windows Server 2003 / SQL Server 2005 数据库传输到 BULL FTP 站点,并且在 BULL 端出现了一些损坏。
select @cmd = 'ftp -s:' + @workdir + @workfilename
exec master..xp_cmdshell @cmd, NO_OUTPUT
文本文件包含 SEP490067,但是当它在 BULL 上打开时,它看起来像这样 ..SEP4.9.0.0.6.7..
在使用 SSIS FTP 组件发送文件并将 IsTransferAscii 开关切换为 True 时,我曾看到过类似的情况可以解决此问题。我的问题是您是否必须在上面的 FTP 命令中设置另一个命令行开关才能使用 ASCII 而不是二进制发送文件?
这是完整的 TSQL
USE [JCB_QSmart]
GO
/****** Object: StoredProcedure [dbo].[FTP_PutFile] Script Date: 06/14/2012 08:56:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[FTP_PutFile]
@FTPServer varchar(128) ,
@FTPUser varchar(128) ,
@FTPPWD varchar(128) ,
@FTPPath varchar(128) ,
@FTPFileName varchar(128) ,
@SourcePath varchar(128) ,
@SourceFile varchar(128) ,
@workdir varchar(128),
@ShowOutput as bit = 0
as
declare @cmd varchar(1000)
declare @workfilename varchar(128)
select @workfilename = 'ftpcmd.txt'
-- deal with special characters for echo commands
select @FTPServer = replace(replace(replace(@FTPServer, '|', '^|'),'<','^<'),'>','^>')
select @FTPUser = replace(replace(replace(@FTPUser, '|', '^|'),'<','^<'),'>','^>')
select @FTPPWD = replace(replace(replace(@FTPPWD, '|', '^|'),'<','^<'),'>','^>')
select @FTPPath = replace(replace(replace(@FTPPath, '|', '^|'),'<','^<'),'>','^>')
select @cmd = 'echo ' + 'open ' + @FTPServer
+ ' > ' + @workdir + @workfilename
exec master..xp_cmdshell @cmd
select @cmd = 'echo ' + @FTPUser
+ '>> ' + @workdir + @workfilename
exec master..xp_cmdshell @cmd
select @cmd = 'echo ' + @FTPPWD
+ '>> ' + @workdir + @workfilename
exec master..xp_cmdshell @cmd
select @cmd = 'echo ' + 'put ' + @SourcePath + @SourceFile + ' ' + @FTPPath + @FTPFileName
+ ' >> ' + @workdir + @workfilename
exec master..xp_cmdshell @cmd
select @cmd = 'echo ' + 'quit'
+ ' >> ' + @workdir + @workfilename
exec master..xp_cmdshell @cmd
select @cmd = 'ftp -s:' + @workdir + @workfilename
create table #a (id int identity(1,1), s varchar(1000))
insert #a
exec master..xp_cmdshell @cmd, NO_OUTPUT
select id, ouputtmp = s from #a