Tuesday, March 27, 2012

FTP from within T-SQL

I am using SQL 2000 on a Win 2k server. I have read some where that
you can fire FTP commands from within t-sql statements.

Something like a stored proc that gets called by a job every night
that would build a recordset and then ftp it out to another server as
a txt file.

I understand that DTS can do something like this, but I would like to
see if it can be handled from within a t-sql procedure.

Curious and stubborn!

Any help would be greatly appreciated.

Thanks,
Davefunkdm1@.yahoo.com (Dave) wrote in message news:<f5174e0f.0405101837.5f6c1e53@.posting.google.com>...
> I am using SQL 2000 on a Win 2k server. I have read some where that
> you can fire FTP commands from within t-sql statements.
> Something like a stored proc that gets called by a job every night
> that would build a recordset and then ftp it out to another server as
> a txt file.
> I understand that DTS can do something like this, but I would like to
> see if it can be handled from within a t-sql procedure.
> Curious and stubborn!
> Any help would be greatly appreciated.
> Thanks,
> Dave

You could use FTP from TSQL in a couple of ways, although it's
debatable if you should or not. The simplest is probably to use
xp_cmdshell to run an external batch file or script which does the
FTP. A more complex option is to use the sp_OA% procedures to work
with a COM component which can do FTP.

If you want to get results into a file, it may be easier to use
bcp.exe or osql.exe in a batch file to get the result set from the
procedure directly into a file, rather than drive it from the stored
procedure itself.

DTS is often a better general option, although the FTP task can only
GET, not PUT. There is an alternative implementation that will do
both, however:

http://www.sqldts.com/?302

Simon

No comments:

Post a Comment