Gaurav
Gaurav

Reputation: 31

Check if file exist on a webserver using sql server

I want to check that a file exists on a web server using the SQL Server.

I have tried the xp_cmdshell DIR. But it works only for local files.

Please let me know how to achieve this.

Thanks in advance.

Upvotes: 1

Views: 1037

Answers (2)

Gaurav
Gaurav

Reputation: 31

After searching for a few days, I found the following which works well :-

When you have to put file, like BCP result, or a backup in a remote drive, just map this drive into windows don't work, it must be mapped on SQL Server to!, to do this, try like this:

exec xp_cmdshell 'net use p:\ \Server\Folder\Folder\Folder\ /Domain\Login /Password'

Reference : https://social.msdn.microsoft.com/Forums/en-US/6eca2d62-eb86-4f23-9b86-6f917017f50c/bcp-utility-via-xpcmdshell-and-network-drive?forum=sqlsecurity

Upvotes: 1

Ajay2707
Ajay2707

Reputation: 5798

You can not access with any user, means while access directory in sqlserver you have to only use that user which have directory rights and your sqlserver services running in that user.

if you access in normal user or say simply Network Service or 'Local Service' user (in which sqlserver service run default) you can access all resources of your computer via network too (ie. \yourname\sharablefolder ), but not access sharable folder in the network.

either backup resore : http://www.sqlservercentral.com/Forums/Topic631787-146-1.aspx

or execute command :

http://www.sqlservercentral.com/Forums/Topic808580-359-1.aspx

how can i access a file/folder over network through XP_CMDSHELL in sql server 2008?

https://www.simple-talk.com/community/forums/thread/72262.aspx

https://social.msdn.microsoft.com/forums/sqlserver/en-US/c5ce5e21-17e7-4763-ba68-d3bb7dad213f/access-denied-on-xpcmdshell-with-certain-folders

Upvotes: 0

Related Questions