Getting Started with Adobe After Effects - Part 6: Motion Blur
A collection of quick technology learning tips from what people around you learn every day

Script to download file via FTP in SQL Server

Nov 21 2011 10:02AM by Paresh Prajapati   

Earlier i submitted script to upload file(s) via FTP in SQL Server here http://beyondrelational.com/justlearned/posts/600/script-to-upload-files-via-ftp-in-sql-server.aspx. You can find here the same but it's for download the file from FTP.

DECLARE
    @FTPServer	varchar(128) ,
    @FTPUser	varchar(128) ,
    @FTPPWD		varchar(128) ,
    @FTPPath	varchar(128) ,
    @FTPFileName	varchar(128) ,
    @SourcePath	varchar(128) ,
    @SourceFile	varchar(128) ,
    @workdir	varchar(128),
    @cmd varchar(1000),
    @workfilename varchar(128)

SET @FTPServer = 'FTP Server Name'
SET @FTPUser = 'FTP User Name'
SET @FTPPWD = 'Password'
SET @FTPPath = '/subfolder1/subfolder2/' -- or '' if not having subfolders
SET @FTPFileName = 'FTP File Name'
SET @SourcePath = 'Local Path for download'
SET @SourceFile = 'Local File Name to be saved as'
SET @workdir = 'C:\FTP\'
SET @workfilename = 'ftpcmd.txt'

-- Writing steps to working file
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
-- Executing steps from working file
EXEC master..xp_cmdshell @cmd
SELECT  @cmd = 'ftp -s:' + @workdir + @workfilename
-- Executing final step
EXEC master..xp_cmdshell @cmd

You can read earlier for the FTP here, http://beyondrelational.com/justlearned/posts/608/upload-all-files-from-source-folder-via-ftp-in-sql-server.aspx (to upload multiple files) and http://beyondrelational.com/justlearned/posts/603/change-transfer-mode-from-ascii-to-binary-for-files-upload-via-ftp-sql-server.aspx (to change file transfer mode).

Read More..   [46 clicks]

Published under: SQL Server Tips ·  ·  ·  · 


Paresh Prajapati
6 · 22% · 7044
6
 
0
Knew
 
 
0
Incorrect
 
0
Interesting
 
0
Forgotten



Submit

Your Comment


Sign Up or Login to post a comment.

"Script to download file via FTP in SQL Server" rated 5 out of 5 by 6 readers
Script to download file via FTP in SQL Server , 5.0 out of 5 based on 6 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]