Home » Questions » Computers [ Ask a new question ]

What is best practice for FTP from a SQL Server 2005 stored procedure?

What is best practice for FTP from a SQL Server 2005 stored procedure?

"What is the best method for executing FTP commands from a SQL Server stored procedure? we currently use something like this:

EXEC master..xp_cmdshell 'ftp -n -s:d:\ftp\ftpscript.xmt'

The problem is that the command seems to succeed even if the FTP ended in error. Also, the use of xp_cmdshell requires special permissions and may leave room for security issues."

Asked by: Guest | Views: 128
Total answers/comments: 3
Guest [Entry]

"If you're running SQL 2005 you could do this in a CLR integration assembly and use the FTP classes in the System.Net namespace to build a simple FTP client.

You'd benefit from being able to trap and handle exceptions and reduce the security risk of having to use xp_cmdshell.

Just some thoughts."
Guest [Entry]

Another possibility is to use DTS or Integration Services (DTS for SQL Server 7 or 2000, SSIS for 2005 or higher). Both are from Microsoft, included in the Sql Server installation (in Standard edition at least) and have an FTP task and are designed for import/export jobs from Sql Server.
Guest [Entry]

"If you need to do FTP from within the database, then I would go with a .NET assembly as Kevin suggested. That would provide the most control over the process, plus you would be able to log meaningful error messages to a table for reporting.

Another option would be to write a command line app that read the database for commands to run. You could then define a scheduled task to call that command line app every minutes or whatever the polling period needed to be. That would be more secure than enabling CLR support in the database server."