SQL FTP下载问题 [英] SQL FTP download problem
本文介绍了SQL FTP下载问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已使用以下查询从FTP下载文件.
SP已成功执行,但未下载文件.
任何机构都可以帮助我通过SQL存储过程从FTP下载文件吗?
I have used below query for downloading a file from FTP.
SP is executes successfully but files are not getting downloaded.
Can any body help me to download file from FTP through SQL Stored Procedure?
Create procedure s_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 s_ftp_GetFile
@FTPServer = 'www.myftpsite.com' ,
@FTPUser = 'myuser' ,
@FTPPWD = 'mypwd' ,
@FTPPath = '' ,
@FTPFileName = 'myfile.html' ,
@SourcePath = 'c:\vss\mywebsite\' ,
@SourceFile = 'myfile.html' ,
@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, '|', '^|'),'<','^<'),'>','^>')
print @FTPServer
select @FTPUser = replace(replace(replace(@FTPUser, '|', '^|'),'<','^<'),'>','^>')
print @FTPUser
select @FTPPWD = replace(replace(replace(@FTPPWD, '|', '^|'),'<','^<'),'>','^>')
print @FTPPWD
select @FTPPath = replace(replace(replace(@FTPPath, '|', '^|'),'<','^<'),'>','^>')
print @FTPPWD
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
create table #a (id int identity(1,1), s varchar(1000))
insert #a
exec master..xp_cmdshell @cmd
select id, ouputtmp = s from #a
GO
推荐答案
看看这个:
使用存储过程通过FTP发送文件 [
Have a look at this one:
Send Files Via FTP Using a Stored Procedure[^]
Looks like you are missing something like this at the end:
set @cmd = 'ftp -s:' + @script_file_path + @script_file_name
exec master..xp_cmdshell @cmd
这篇关于SQL FTP下载问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文