Pages

Sunday, November 11, 2012

Using Putty - Plink, PSFTP in QTP


When I started working on QTP initially, I was always questioned about how to run command and copy files and folders from backend.

Situation 1:


I had to use only a particular username and password assigned for automation test team and the test should be run any users who is using QC (with BPT) so I had issues concerning security issues of storing username and passwords in "Components" or in Data Sheet.

Finally I had a solution of using .ppk file where my private public key is saved in a common path. But then I cannot use Putty with this so I had to use Plink to run my batch and then use PSFTP to download files / Folders from backend.

Here I will show you step by step procedure on using Plink and PSFTP in QTP.

1. Make sure you have Putty installed in the machine if so go to step 2, Else download Putty.

2. To start using Plink, (which is usually installed in the same location as Putty) Click on RUN from windows and type cmd, which opens the Command Line and use command prompt

for example if your putty directory is in C:\Program Files\putty, type

cd<Space>C:\Program Files\putty

-       This will change your directory to putty and now use the following to use this is QTP.

to use this in QTP

systemutil.run (filename,[parameters],[path],[operation],[mode])

SystemUtil.Run ("cmd")

Window ("object class:=ConsoleWindowClass").Type cd C:\Program Files\putty

Window ("object class:=ConsoleWindowClass").Type micReturn

Now use the username and password to login to (Unix/Linux/Remote machine) whatever you call it as and run the command. For example

          plink –i “path where you have stored the .ppk file” –l username machineid

once after logged in the machine use Type command and run the batch.

Now after running the batch say for example if you need to copy a folder to local machine for some reason, I found it very difficult….. finally had a solution for this.

Situation 2:

To copy the files to local machine use the command “mget” in PSFTP.

For which use the same method illustrated above to login in PSFTP

Ex  ------  psftp –ssh -pw <password> –l <username> machineid


After logging in use command cd<space> and the directory you want to change to

Ex -----  cd /remote/users/ram

Now set the local directory before copying the files, and always use the local path values in quotes as if your file or folder has space oin it then you will get some error.

Ex -------- lcd “C:\Users\Ram - PC\file copy” as you see there is space in the directory name , so it is always good to use local path values in quotes

Now that your local path is set, use the following command to get all files and folders recursively to your local machine.

Ex ------- pstfp> mget -r testdir/folderName/*

The * at the end of the folder name will copy all files and mget –r will make sure all files and folder is copied recursively

Similarly if you upload a file use the command mput -r testdir/folderName/*

Hope this post was useful.



This is my first blog on Quick Test Professional (QTP) and Quality Centre as I always wanted to share some of the common question in QTP and QC