2

Is there way to get file from windows xp command prompt? I tried to run xp_cmdshell 'type [path to file]' but then when i insert theese data into other file and renaming it to file.exe (that is executable) it does not work. Any suggestions how to get file contents in such way that i can use it?

seeker
  • 3,255
  • 7
  • 36
  • 68
  • What is xpcmdshell? Do you mean the SQL extended stored procedure, xp_cmdshell? – Harry Johnston May 20 '12 at 19:24
  • 1
    Probably you need to convert the binary data into text form and back, e.g., base64 encoding. AFAIK there is no way to do this using only built-in Windows utilities. Can you make use of a third-party application, or are you limited to what is already on the server? – Harry Johnston May 22 '12 at 01:39
  • I am limited only to console, I cannot install anything. When I try to see content of text file with Latin chars, it works. Otherwise not. And could you link me to example of binary data conversion? – seeker May 22 '12 at 08:43
  • 1
    http://en.wikipedia.org/wiki/Base64 – Harry Johnston May 22 '12 at 09:37

1 Answers1

1

You could use BULK INSERT on the file and treat the file as a table with one row and one column. This should allow you to read the file directly into a VARBINARY field

Like this:

CREATE TABLE FileRead
(
  content VARBINARY(MAX)
)

BULK INSERT FileRead FROM [FilePath]

This requires SQL Server to have access to the file you are trying to read. It sounds like you are trying to "acquire" executables from a server you do not have access to? :-)

Thomas Kejser
  • 1,264
  • 1
  • 10
  • 30