May 22, 2006 at 9:38 pm
Hi,
In the same machine, I can run the following PSCP command to fetch a
file from remote server from a command window:
C:\Download\Putty\pscp.exe -p -pw xxxx@xxxx
name@serverIP:/export//detail-20060518.csv
C:\Temp\Test\detail-20060518.csv
But when I run it in SQL Sever Query Analyzer (log in as 'sa')
Exec master..xp_cmdshell 'C:\Download\Putty\pscp.exe -p -pw xxxx@xxxx
name@serverIP:/export//detail-20060518.csv
C:\Temp\Test\detail-20060518.csv'
I always get the following error message:
The server's host key is not cached in the registry.......... Store key
in cache? (y/n) Connection abandoned
What I am trying to do is to schedule a job to run the above command
Any ideas/suggestions please.
Thanks in advance.
Bob
May 24, 2006 at 12:27 am
Hello Bob,
I think you had to run (once per ssh server) pscp with the account impersonified by sql server and sql server agent in order to have pscp create the registry key
andrea
May 25, 2006 at 11:52 pm
Hi Andrea,
Thanks for the reply, but HOW CAN I DO THAT ? I tried login as 'sa' and/or Windows Authorization account (I installed the SQL Server in that machine), open Query Analyzer to run the above script, got the same error message.
If you can please provide more details, or a link to reference site/pages would be highly appreciated.
Bob
May 25, 2006 at 11:59 pm
I think, you had to logon on the machine with the same account showned on services snap-in for SQL server agent and mssqlsever services; if these ones are all localsystem i think is better for you to change the account (from enterprise manager, it's more sure).
Once you have logged you had to make a connection with pscp and caching the server's key on the registry so it is available to the services.
andrea
May 27, 2006 at 11:38 pm
Why not go for the simple method... schedule it with Windows Task Scheduler if you can't get it to run through the command shell.
--Jeff Moden
Change is inevitable... Change for the better is not.
September 6, 2007 at 11:36 pm
I know this is a very old thread but I have yet to see a solution to this problem if your SQL Server is running as the local system account - so here it is!
1. Create a text file with the letter Y and a carriage return in it:
For examle :
Y
<blank line>
2. at the end of pscp command add the following:
< <name_of_your_text_file_created_in_step_1>
THATS IT !!
Basically, the less than character '<' will redirect the contents of the text file to the input of the pscp command, answering the prompt automatically for you.
Hope this is of some help to somebody sometime.
October 11, 2007 at 10:37 am
Log into the server either at the consul or through RDC as the user that starts the SQL service
Create the connection to the SSH server
putty.exe
Save the RSA hash to the registry
Now when the scheduled job runs it will have the hash saved
July 25, 2008 at 9:21 am
Thats a real good advice by James!!!!
November 20, 2008 at 8:52 am
Thank you so much for that Tip, James! Had the same problem with psftp, works fine right now!
March 24, 2009 at 10:53 am
Thanks for the post. Adding that file with the "Y" did the trick. I hate working blind with xp_cmdshell but I guess you deal with it.
April 21, 2009 at 7:55 pm
H James,
Thank you, we just used your tip (adding Y to a file) and our pscp command works fine from SQL Server now.
Thanks again,
Praveena
June 24, 2009 at 6:53 am
Thanks for your post James, it worked for me too.
Just to add to it,
I had to put whole path for the text file, without which it was complaining 'The system cannot find the file specified'. So my command in the BAT file is now:
D:\psftp.exe -be -pw Password -v -bc -b d:\BatFileWithUNIXCommands.bat LoginName@IPAddress < D:\yes.txt
James Rizzo (9/6/2007)
I know this is a very old thread but I have yet to see a solution to this problem if your SQL Server is running as the local system account - so here it is!
1. Create a text file with the letter Y and a carriage return in it:
For examle :
Y
<blank line>
2. at the end of pscp command add the following:
< <name_of_your_text_file_created_in_step_1>
THATS IT !!
Basically, the less than character '<' will redirect the contents of the text file to the input of the pscp command, answering the prompt automatically for you.
Hope this is of some help to somebody sometime.
August 11, 2009 at 7:59 am
Hi All,
I am experiencing the same issue in relation to the Servers host key. Unfortunately I have not been able to get James’ fix to work.
My set up is as follows:-
SQL Server and SQL Server Agent both run under Local\System
The code I am trying to run is as follows:-
DECLARE @sDosCommand VARCHAR(90)
SET @sDosCommand = 'D:\Putty\pscp -q -batch -scp -C -pw Password -l user UserName@IPAddress:F:/Testfile.txt F:/ < D:\Putty\Important.txt'
EXEC master..xp_cmdshell
@sDosCommand
Note Important.txt has Y and the carriage return lines in it.
If I run the above form the command line it works perfectly (due to the host key for the logged in User already been generated). However when I run it from within a ISQL session (logged in as the SA account), ISQL hangs as it waits for the relevant response to its Hash prompt (required as it wants to create one based on SQL Server Agents, Service account ie. Local\System)
As you can see I have tried James’ trick by using the input pipe reference, but to no success.
Can anyone show me where I am going wrong.
Many thanks
Darren
August 11, 2009 at 8:06 am
What's 'carriage return lines' ?
I have just 'Y' in mine without anything else in it, which works for me.
darrenkelly (8/11/2009)
Hi All,I am experiencing the same issue in relation to the Servers host key. Unfortunately I have not been able to get James’ fix to work.
My set up is as follows:-
SQL Server and SQL Server Agent both run under Local\System
The code I am trying to run is as follows:-
DECLARE @sDosCommand VARCHAR(90)
SET @sDosCommand = 'D:\Putty\pscp -q -batch -scp -C -pw Password -l user UserName@IPAddress:F:/Testfile.txt F:/ < D:\Putty\Important.txt'
EXEC master..xp_cmdshell
@sDosCommand
Note Important.txt has Y and the carriage return lines in it.
If I run the above form the command line it works perfectly (due to the host key for the logged in User already been generated). However when I run it from within a ISQL session (logged in as the SA account), ISQL hangs as it waits for the relevant response to its Hash prompt (required as it wants to create one based on SQL Server Agents, Service account ie. Local\System)
As you can see I have tried James’ trick by using the input pipe reference, but to no success.
Can anyone show me where I am going wrong.
Many thanks
Darren
August 11, 2009 at 8:16 am
Hi umertahir
Wow that was a prompt reply 🙂
In James post he said to add two lines to the file
Line 1: Y
Line 2: carriage return
Thats what I have in my file, however as noted by you, you only have Y, so I tried only having that in my file, but unfortuately it didn't overcome my issue.
I am begining to think now, the problem may relate to limitations with xp_cmdshell, but still throwing different permatations at it
Darren
Viewing 15 posts - 1 through 15 (of 23 total)
You must be logged in to reply to this topic. Login to reply