sql-server - 在远程服务器中执行 xp_cmdshell

标签 sql-server t-sql

RECONFIGURE
EXEC sp_configure 'xp_cmdshell',1  

declare @cmdstring varchar(1000)

set @cmdstring = 'copy D:\\Mine\\Mine\\Icons\\1355312509_gadu.ico D:\\Mine\\Mine\\1355312509_gadu.ico'
exec master..xp_cmdshell @cmdstring 

RECONFIGURE
EXEC sp_configure 'xp_cmdshell',0

我正在尝试在远程服务器上执行此操作,我以系统管理员身份登录,但无法执行,这是我收到的错误,我已经完成了之前的帖子,但找不到正确的解决方案

output
The device is not ready.
NULL

如有任何帮助,我们将不胜感激

这段代码不会吗

RECONFIGURE
    EXEC sp_configure 'xp_cmdshell',0 

在代码末尾消除那些安全威胁?

这就是我所做的,没关系

CREATE TABLE #temp
(
    id               INT IDENTITY(1, 1),
    name_file        VARCHAR(500),
    depth_tree       VARCHAR(10),
    is_folder_files  VARCHAR(10)
)

/* xp_dirtree selects file from specific location
*  depth_tree       :   depth of the search i.e. subfolders
*  is_folder_files  :   selects folders only or files too
*/

INSERT INTO #temp(name_file, depth_tree, is_folder_files) EXEC xp_dirtree @source_path, 0, 1

-- Must concatenate to have permission for xp_cmdshell
SET @concatenate_string = 'RECONFIGURE EXEC sp_configure ''xp_cmdshell'',1 EXEC MASTER..xp_cmdshell '


-- Generating copy string in bulk
SELECT @cmd_string =    
    ISNULL(@cmd_string, '') + 
    CASE WHEN (LEN(REPLACE(t.name_file, @seperate_value, 1)) <> LEN(t.name_file)) -- if @seperate_value is not in image
        THEN
        (
            SELECT CASE 
                WHEN REPLACE(t.name_file, 'Approach', 1) <> t.name_file OR REPLACE(t.name_file, 'CloseUp', 1) <> t.name_file -- if word Approach or CloseUp is not there in image 
                THEN
                    (
                    SELECT CASE
                    WHEN ((SELECT f.FaceID FROM Face f WHERE CAST(f.Notes AS VARCHAR) = SUBSTRING(t.name_file, 0, CHARINDEX(@seperate_value, t.name_file)-1)) IS NOT NULL) -- when extracted ID from image <> NotesID
                    THEN
                    (
                    @concatenate_string + '''copy ' + @source_path + t.name_file + ' ' 
                    + @destination_path 
                    + (SELECT f.FaceID FROM Face f WHERE CAST(f.Notes AS VARCHAR) = SUBSTRING(t.name_file, 0, CHARINDEX(@seperate_value, t.name_file)-1)) -- Compares and gives the faceID
                    + (SELECT   CASE 
                                    WHEN REPLACE(t.name_file, 'Approach', 1) <> t.name_file THEN '-AS.jpg'' '
                                    WHEN REPLACE(t.name_file, 'CloseUp', 1) <> t.name_file THEN '-BS.jpg'' '
                                    ELSE
                                        'Undefined'
                                END
                       )
                    )
                    ELSE
                        ' '
                    END
                )
                ELSE
                    ' '
                END
        )    
        ELSE
            ' '
    END

FROM #temp t

SELECT @cmd_string + 'RECONFIGURE EXEC sp_configure ''xp_cmdshell'',0'

EXEC (@cmd_string)

最佳答案

我也有过这样的经历。我从服务器 a 运行脚本,其中的内容位于服务器 b 上。我检查了,唯一的事情(除了凭据,看起来这不是问题)是远程服务器上不存在文件结构..

关于sql-server - 在远程服务器中执行 xp_cmdshell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14919382/

相关文章:

.net - 如何确保连接字符串用于本地计算机

sql - sql server中如何将列转换为行

sql-server - 如何在 SQL Server Management Studio 中连接到本地数据库?

SQL语句-更新两个表

SQL - 另一个 Select 语句的 Where 子句?

sql - 存储过程不返回任何内容

mysql - 从 SQL Server 迁移到 MySql

sql-server - 我们可以在 select 语句中使用 EXEC()

sql - 选择只有一个订单且该订单满足某些条件的所有用户

sql - Microsoft SQL 查询使用过度分区获取 DISTINCT 值的计数