Pergunta

I have a C# .Net console app performing an ftp copy runs from the cmd command prompt, but when run from a SQL agent job or from SQL server management studio, the FTP part of the app fails:

declare @cmd varchar(200)
select @cmd = 'c:\ftptest\test.exe';
exec master..xp_cmdshell @cmd ;

The console application when run from command prompt does the FTP file upload but throws an exception when using the SQL route:

System.Net.WebException: The remote server returned an error: (400) Bad Request.
at System.Net.FtpWebRequest.GetResponse()

This sounds like a permissions problem but the same user is running the console app in both the SQL Server Management Studio query and from the command prompt and both are running on the same server.

Foi útil?

Solução 2

SSMS was using a xp_cmdshell_proxy_account for xp_cmdshell and I managed to solve the problem simply through proxy configuration in app.config of my console app:

<system.net>
   <defaultProxy
      enabled="false"
      useDefaultCredentials="false"
    />
</system.net>

Outras dicas

First, xp_cmdshell should run in the security context of an SQL Server service account.

Considering that, your service shouldn't run if your service acc doesn't have enough privilege (probably LocalService or even NetworkService won't do). Check that in SQL Server Configuration Manager.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top