Professional Web Applications Themes

Copying and moving files... - Microsoft SQL / MS SQL Server

Hello... Due to security reasons... is there another way that I am able to copy and move files (for example copying or moving a text file from one directory location to another) without using xp_cmdshell? I was thinking... is it possible to do it in script... if so what would the syntax look like? Please advise... Thanks, Brett M. Davis MCP...

  1. #1

    Default Copying and moving files...

    Hello...

    Due to security reasons... is there another way that I am
    able to copy and move files (for example copying or moving
    a text file from one directory location to another)
    without using xp_cmdshell?

    I was thinking... is it possible to do it in script... if
    so what would the syntax look like?

    Please advise...

    Thanks,

    Brett M. Davis MCP


    Brett Guest

  2. #2

    Default Re: Copying and moving files...


    "Brett" <net> wrote in message
    news:008401c34ae9$160975e0$gbl... 

    You can use the Scripting.FileSystemObject through the sp_OA* procedures.

    Here's the only example I have on hand. It writes to text files.

    Anyway look in the reference for the FSO, it can copy and move files etc.

    David



    create procedure file_write_text(file_name varchar(1000),
    text varchar(8000),
    append bit = 0)
    as
    /*
    exec file_write_text 'c:\foo.txt','hello'
    exec file_write_text 'c:\foo.txt',' world',1
    */

    declare fso int
    declare ts int
    declare rv int

    exec rv = sp_oacreate "scripting.filesystemobject", fso OUTPUT, 1
    if rv <> 0 goto eh
    if append = 1
    begin
    --open the text stream for append, will fail if the file doesn't exist
    exec rv = sp_oamethod fso,"opentextfile", ts OUTPUT, file_name, 8
    if rv <> 0 goto eh
    end
    else
    begin
    --create a new text file, overwriing if necessary
    exec rv = sp_oamethod fso,"createtextfile", ts OUTPUT, file_name, -1
    if rv <> 0 goto eh
    end
    exec rv = sp_oamethod ts,"write",null ,text
    if rv <> 0 goto eh
    exec rv = sp_oamethod ts,"close"
    if rv <> 0 goto eh

    exec sp_oadestroy ts
    exec sp_oadestroy fso

    return 0

    eh:
    declare es varchar(512)
    declare ed varchar(512)
    exec sp_oageterrorinfo null, es OUTPUT, ed OUTPUT
    raiserror(ed,16,1)
    exec sp_oadestroy ts
    exec sp_oadestroy fso
    return 1



    David Guest

Similar Threads

  1. Question problems copying or renaming files unlock delete files
    By anhgun123 in forum Brainstorming Area
    Replies: 1
    Last Post: February 27th, 11:34 AM
  2. copying files into site
    By Joris van Lier in forum Macromedia Exchange Dreamweaver Extensions
    Replies: 3
    Last Post: October 8th, 06:59 PM
  3. .PSB and (not) copying 1.99+ Gb files to server(s)
    By spclark@adobeforums.com in forum Adobe Photoshop Mac CS, CS2 & CS3
    Replies: 14
    Last Post: April 27th, 03:10 PM
  4. Copying files from the cd?
    By Akhtar Ali webforumsuser@macromedia.com in forum Macromedia Director Basics
    Replies: 1
    Last Post: July 5th, 10:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139