我正在使用此代码将文件从本地系统传输到ftp(我拥有此ftp的所有读写权限)。
if exists (select * from sysobjects where id = object_id(N'[dbo].[s_ftp_PutFile]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[s_ftp_PutFile]
GO
Create procedure s_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)
as
/*
exec s_ftp_PutFile
@FTPServer = '172.*****' ,
@FTPUser = 'username' ,
@FTPPWD = 'password' ,
@FTPPath = '/dir1/' ,
@FTPFileName = 'test2.txt' ,
@SourcePath = 'c:\vss\mywebsite\' ,
@SourceFile = 'test2.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 ' + '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
select id, ouputtmp = s from #a
go
我无法传输文件并收到此错误
1位用户(172。****** :(无)):打开172。******
2 NULL
3 NULL
4放c:\ vss \ mywebsite \ test2.txt /dir1/test2.txt
5 c:\ vss \ mywebsite \ test2.txt:找不到文件
6退出
7 NULL
但是我可以通过cmd提示传输。
答案 0 :(得分:0)
可以sql做命令行的其他事情吗?
另外,uid ss在命令行上使用,是否有权从ss机器到目的地进行通话?许多企业不允许“服务”ID通过网络毫无疑问地与任何想要的人交谈。它可能需要建立连接的权利。