Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stored proc xp_cmdshell hangs

Status
Not open for further replies.

p27br

Programmer
Aug 13, 2001
516
GB
hi there,

i have the following SP that connects to a remote FTP server and should download all files with the name preview.*.txt from the given folder.
I am using xp_cmdshell to execute the FTP commands but the files aren't getting downloaded to the folder c:\tmp
the QA just hangs.

Code:
CREATE procedure s_ftp_GetFiles
@FTPServer	varchar(128) ,
@FTPUser	varchar(128) ,
@FTPPWD	varchar(128) ,
@FTPPath	varchar(128) ,
@workdir	varchar(128)
as

declare	@cmd varchar(1000)
	
	-- 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, '|', '^|'),'<','^<'),'>','^>')

	exec master..xp_cmdshell @cmd
	select @cmd = 'open ' + @FTPServer
	exec master..xp_cmdshell @cmd
             select @cmd = 'user ' + @FTPUser + ' ' + @FTPPWD
	exec master..xp_cmdshell @cmd
             select @cmd = 'ls ' + @FTPPath
	select @cmd = 'cd ' + @workdir
            select @cmd = 'toggle prompt'
	select @cmd = 'mget preview.*.txt'
	exec master..xp_cmdshell @cmd
GO

here is the command I enter in the QA window
Code:
exec s_ftp_GetDir '255.255.255.0','john','foo','/incoming/','c:\tmp'
 
Won't work that way - you must supply all FTP commands in one command shell. I'm not sure this is even possible without additional FTP scripting tools or SQL2k packages (File Transfer task).

------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
[banghead]
 
well ideally i'd like to wrap it all up in a DTS package, using the FTP task.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top