Get file contents via xp_cmdshell

2020-07-25 23:25发布

问题:

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?

回答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? :-)