Hommer
Aged Yak Warrior
808 Posts |
Posted - 2007-11-02 : 11:19:54
|
I have to use a stored proc that I found from here to do the job.Then in SSIS, add a exec sql step to call it.You have to enable the cmd shell on the sql server surface management to use this.Other conditions include: the file name is known, and has created a folder on C:\temp for the script file.Create procedure ps_ftp_GetFile @FTPServer varchar(128) , @FTPUser varchar(128) , @FTPPWD varchar(128) , @FTPPath varchar(128) ,@FTPFileName varchar(128), @SourcePath varchar(128), @SourceFile varchar(128), @workdir varchar(128) AS/* exec ps_ftp_GetFile @FTPServer = 'ftp.site.com' , @FTPUser = 'FTPuser' , @FTPPWD = 'pwd' , @FTPPath = '/xyz/' , @FTPFileName = 'impFile.txt' , @SourcePath = '\\myUNC\' , @SourceFile = 'impSFile.txt' , @workdir = 'c:\temp\' */ 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 ' + 'get ' + @FTPPath + @FTPFileName + ' ' + @SourcePath + @SourceFile + ' >> ' + @workdir + @workfilename exec master..xp_cmdshell @cmd select @cmd = 'echo ' + 'quit' + ' >> ' + @workdir + @workfilename exec master..xp_cmdshell @cmd select @cmd = 'ftp -s:' + @workdir + @workfilename |
 |
|