Issues with automating SFTP command

Hi All,

I am currently looking at automating the steps that I follow to download log files from putty to desktop.

I connect to a client's machine through citrix desktop. I am required to download quite a number of application logs to identfiy the issues in production.

Steps that is being followed now:

  1. open putty.exe enter the host name or ip address(art01.wrs.aps-bcs.org)-- this is a stepping stone server
  2. Once I click on okay. I get a prompt window with a message login as, after I enter the user name I enter the password.
  3. Next I see a "bash >" Now I enter the box to which I have to connect to. It would look like bash> sftp cdsapptl01
  4. Now I am asked to enter the password. After that I will have to enter the path of the log file and do a mget.
  5. I connect to toad and move the file from server to desktop

So far so good.

I am looking at automating the above steps so that I can run a .bat file to perform the operation.

What I've done so far:

Created a test.bat, it would look like:
CALL putty.exe -load art01.wrs.aps-bcs.org -l username -pw password

When I run this batch file I am directly on to step 3. Makes me feel proud that I got thus far given the fact that I havent worked on scripting or unix.

Next I modified the test.bat to look like :
CALL putty.exe -load art01.wrs.aps-bcs.org -l username -pw password -m command.txt
the command.txt would look like this:
sftp cdsapptl01 (I also tried adding the password to this server in the same line i.e., sftp cdsapptl01 -pw password)

In both the cases what hapens is the prompt window ges closed automatically.

I am looking at the next steps now. I need to add the sftp cdsapptl01 and the password and its path lastly the mger command to download the log file.

So when I run the batch file it should call the command.txt and all the lines should be executed including the mget so that the log file is downloaded.

Can someone please help me in this regard?I am required to complete this task by 9th January. Any help is highly appreciated. Thanks in advance!

i have not worked on automating putty before but i suspect your issue is that putty is closing your original connection to art01 to start a connection to cdsapptl01 ... check if you can use redirection (see here document) ... if not, see if you can sftp directly to cdsapptl01 with putty or winscp ...

good luck!

Thanks for your response Just Ice. I do not have winscp and as I said I work on a client's machine thro' citrix so I do not have an option to install other softwares/tools. I am adding fuel to the fire here. I cannot sftp directly to cdsapptl01. I need to get there via art01, the stepping stone server. :frowning:
A good news here, I've got myself 10 days more to complete this task.

By the way, hardcoding passwd is not a good idea, you'd better setup an ssh connection (generate private key with puttygen.exe) setup your public key into your ~user/.ssh/authorized_keys file on the step server.
Run the putty agent
you can make a shortcut on your desktop so that it load your private key automagically, you just have to enter your passphrase:
example in the properties of your shortcut to launch the puttyagent so that it will provide your public authentication to your further putty session without prompting you whe you log to the remote step serv:

"C:\Program Files\PuTTY\pageant.exe" D:\whtever_path_yr_private_key_is_in\your_private_key.ppk

Add the path of your private key in the setup of your PuTTY session.