在DOS命令下(或Bat文件)执行:
net use //192.168.100.1/ipc$ ks-c-001-11 /user:administrator
COPY //192.168.100.1/xm/XM/SALE_DBC.* c:/temp /y
COPY //192.168.100.1/xm/XM/sale07.* c:/temp /y
COPY //192.168.100.1/xm/XM/sale10.* c:/temp /y
COPY //192.168.100.1/xm/XM/sale11.* c:/temp /y
net use //192.168.100.1/ipc$ /del
查询分析中下执行:
1.使用xp_cmdshell,最好在命令前加上”master.dbo.”,因为存储过程“xp_cmdshell”属于master数据库。
2.在设置连接IPC时,”user:”和”用户名”之间还要加上连接的IP或电脑名称.
一、使用IP地址连接
–1.设置连接
EXEC master.dbo.xp_cmdshell ‘net use //192.168.100.1/ipc$ ks-c-001-11 /user:192.168.100.1/administrator’
–2.执行dos命令
EXEC master.dbo.xp_cmdshell ‘COPY //192.168.100.1/xm/XM/SALE_DBC.* c:/temp /y’
EXEC master.dbo.xp_cmdshell ‘COPY //192.168.100.1/xm/XM/sale07.* c:/temp /y’
EXEC master.dbo.xp_cmdshell ‘COPY //192.168.100.1/xm/XM/sale10.* c:/temp /y’
EXEC master.dbo.xp_cmdshell ‘COPY //192.168.100.1/xm/XM/sale11.* c:/temp /y’
–3.断开连接
EXEC master.dbo.xp_cmdshell ‘net use //192.168.100.1/ipc$ /del’
二、使用电脑名称连接
–1.设置连接
EXEC master.dbo.xp_cmdshell ‘net use //ks-008/ipc$ ks-c-001-11 /user:ks-008/administrator’
–2.执行dos命令
EXEC master.dbo.xp_cmdshell ‘COPY //ks-008/xm/XM/SALE_DBC.* c:/temp /y’
EXEC master.dbo.xp_cmdshell ‘COPY //ks-008/xm/XM/sale07.* c:/temp /y’
EXEC master.dbo.xp_cmdshell ‘COPY //ks-008/xm/XM/sale10.* c:/temp /y’
EXEC master.dbo.xp_cmdshell ‘COPY //ks-008/xm/XM/sale11.* c:/temp /y’
–3.断开连接
EXEC master.dbo.xp_cmdshell ‘net use //ks-008/ipc$ /del’
原创文章,作者:306829225,如若转载,请注明出处:https://blog.ytso.com/233672.html