Question

I have a command that I wrote in a command prompt which is intended to use psftp.exe to connect to a remote server and retrieve files from it before removing them. When I run it in command prompt it works perfectly. When I try to put it into the command window of a SQL agent job and then run the job it just hangs. Looking at the command is there anything that would cause this?

I have heard that if an executable displays a prompt then it will cause this behaviour but of course psftp.exe does not so I dont think this is the issue.

I am running the job under my local user which has full admin rights also.

I should add that the command in the job will open a text file in order to read out the commands for psftp.exe. I have included the commands for this also.

Main CmdExec Command:

W:\Software\psftp\psftp.exe -pw password1 -b W:\Software\psftp\Retrieval.txt -batch account@123.123.123.123

Text File psftp.exe commands

cd out
lcd "C:\Documents and Settings\MyUser\My Documents\"
mget /out/*.txt
rm /out/*txt
quit
Was it helpful?

Solution

The issue here was twofold. Firstly was that the SQL Agent Job was running under a 'service' account on our production server. This is a seperate user account on our server used for the running of services etc. Although not an issue in itself it was the underlying cause as I will explain.

When I first ran PSFTP.exe manually while coming up with a solution to the requirements (read as managers loosely coupled explanation) I was asked to add a key to the registry. I didnt take note of this and it bit me in the behind when I came to want to automate the process. As I was running under the local user for the most part while debugging via the command line I never had any problems. When I tried to place the batch files etc into a SQL Agent job I effectively changed the user that I was running under as we always use our 'service' user account for jobs such as this. This user of course would not have had the registry key added for the connection to the external sFTP server.

To fix this issue I had to run the PSFTP.exe program manually under the seperate user (by logging into the machine under the 'service' account) and add the registry key. After doing this the SQL Agent job ran successfully. Such a simple thing but it caused me a lot of headache as of course I was not being presented with any exceptions or logs.

OTHER TIPS

Would it be something simple like a password issue? Have you checked the Event Log? Can you post the Event log report here?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top