Usp_copy_unzip_dirfiles--Copy, unzip, list file names from the FTP folder to work Folder

Source: Internet
Author: User

CREATE PROC Usp_copy_unzip_dirfiles
@FTPPath NVARCHAR (4000) = ",--FTP folder path
@WorkPath NVARCHAR (4000) = ",--Work folder path
@FileName NVARCHAR (4000) = ",--file name
@sqlCmd NVARCHAR (4000) = ",--the cmd command to execute
@RegRule nvarchar (4000) = ' Regex*.zip ',--the rule that defines the file name to be copied
@7zippath NVARCHAR (4000) = ' ipcc$\ ' program Files ' \7-zip\7z.exe ',--the principle is called 7z decompression software decompression, so the IPC corresponds to the corresponding network disk path
@IsZipped BIT = 1--Input parameters, confirm that the copy is not a compressed file, only the compressed file, the following script decompression section to be executed
As
SET @sqlCmd = ' dir/b ' [email protected][email protected]
IF object_id (' tempdb.. #dirlisttab ') is not NULL
DROP TABLE tempdb: #dirlisttab
CREATE TABLE tempdb. #dirlisttab
(
FILENAME Nvarchar (128)
)


INSERT into #dirlisttab
EXEC xp_cmdshell @sqlCmd
--select * from #dirlisttab

DECLARE file_cur CURSOR LOCAL STATIC forward_only for
SELECT [FILENAME] from #dirlisttab
OPEN File_cur
While 1=1
BEGIN
FETCH NEXT from File_cur to @FileName
SET @sqlCmd = ' copy ' [email protected][email protected]+ ' [email protected][email protected]
Print @sqlcmd
EXEC xp_cmdshell @sqlcmd

IF (@IsZipped = 1)
BEGIN
SET @sqlCmd = @7zippath+ ' x ' [email protected][email protected]+ '-y-aos-o ' [email protected]
Print @sqlcmd
EXEC xp_cmdshell @sqlcmd
END

If @ @fetch_status <> 0 break;
END
CLOSE File_cur
Deallocate file_cur
SET @sqlCmd = ' dir/b ' [email protected]+ ' *.txt > ' [email protected]+ ' Filename|del ' [email protected]+ ' *.zip/q '
Print @sqlcmd
EXEC xp_cmdshell @sqlcmd
DROP TABLE tempdb: #dirlisttab
GO

Usp_copy_unzip_dirfiles--Copy, unzip, list file names from the FTP folder to work Folder

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.