Link to home
Start Free TrialLog in
Avatar of Shannon Adams
Shannon Adams

asked on

Help with automated PSCP transfers between Windows & Linux

I need to setup automated file transfers between Windows 2008 and RHEL 5 servers.  The batch job will be on the Windows 2008 server.  I used PuTTYgen to create a public/private keypair.  Here is what I need help with:

   - Using PSCP, I need to find out how to use a keypair to transfer the files back and forth without a password.
   - Create a batch file on the Windows server to:
     - See if there is a trigger file on the Linux end (/tmp/out/trigger)
     - try to transfer it, and see if the transfer succeeds or fails.
     - If there is no trigger file, bail out.
     - If there is a trigger file, copy the files using PSCP from the Linux server to Windows (C:\Files)
     - When complete, move the files on the Linux end (using PLINK?) giving Linux the "mv" command on the command line (mv /tmp/out/ /tmp/out/archive) - overwrite anything already in ../archive

Any help getting this setup is appreciated.
Avatar of arnold
arnold
Flag of United States of America image

Your windows 2008 server will need to have the putty app that contains the key running.
You would need to add the public key component from the generated key into the account on the RHEL box $home/.ssh/authorized_keys $home/.ssh/authorized_keys2 rsa2 and DSA keys go into the second.

As long as you do not set a passphrase on the key generated using puttygen
pscp.exe -R path_to_dir/ username@rhelsystem:/path/where/you/want/them

The difficulty in your case is likely that a batch file might run without the user being logged on which might present a problem with not being to have access to the putty key manager for the interchange.

Any possibility of doing the reverse either by sharing the folder and have the Linux box access it using an Samba interface or add the UNIX tools to Windows and share the location using NFS allowing the Linux box to be the initiator of the data transfer?
Avatar of Shannon Adams
Shannon Adams

ASKER

Thanks for the suggestion.  I have been advised that using a Samba or NFS share between the servers is not an option.  If you don't mind, I could use guidance on the trigger part of my question.   i.e. incorporating this in my batch file:

     - See if there is a trigger file on the Linux end (/tmp/out/trigger) - try to transfer it, and see if the transfer succeeds or fails.
     - If there is no trigger file, bail out.
     - If there is a trigger file, copy the files using PSCP from the Linux server to Windows (C:\Files)
     - When complete, move the files on the Linux end using PLINK giving Linux the "mv" command on the c

Thanks for any additional help.
Since you are originating the transfer from the Windows box, trying to rely on a trigger on the remote box is a rather difficult mechanism.
Usually, commonly, the trigger is on the system where the script runs.

One option. Is to use a script on the remote side that when executed checks whether the triggering reference is present that issues an OK As a response while at the same time deleting the trigger file.
#!/bin/sh
trigger_file='/path/to/trigger/file'

[ -f "$trigger_file" ] && echo "OK" && /bin/rm "$trigger_file" 

Open in new window


Now from your windows batch file you would need to run an ssh to connect and run the script looking for the response.

Is it possible for you to use Cygwin rather than putty? Cygwin has also an option to run an ssh server.....

it might be possible with Cygwin to have the public/private keys stored in the user profile without the need to rely on the putty system tray app for key exchange/........

Value=$(ssh user@remote '/path/to/script_to_check_on_trigger')
Test that value is OK and then run your scp while all done withi the Cygwin environment..........

The other option is that your Windows setup. Transfer filesblindly on its schedule (requirement that the files be uniquely named as to not overwrite files already there)
On the Linux side you would have a processing script that will act in the transferred files when the trigger files set.


...

The dilemma you have is what is to happen with the files transferred I.e. Is there aspecific logic that either generates these files or what needs to be extracted from them.
I misread the direction of the transfer.
In your case transfer files from Linux to windows with the script/processing on Windows involves three steps.
On the Linux side you have a trigger file whose content lists the files to ve transferred.
After processing, the Windows side has to transfer the trigger file with the files transferred so the second part on the Linux side will clear out the files already transferred to avoid the inevitable I.e. Running out of space, or the file names used overwrite an existing files or attempting to write and being denied when the file already exists, deals with copy option that does not include overwrite rights....
Any chance you can give me some example code to put in the batch file for this?
ASKER CERTIFIED SOLUTION
Avatar of arnold
arnold
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Rather than using cygwin, it's probably easier to do this from the linux side with a SAMBA mount of the Windows 2008 file system.  You can then write a bash script to catch everything and do the move all in one swoop.

Also, you could create a SAMBA share on linux, then you can just use regular windows scripts to check for the trigger file.  You could write a powershell or batch script to check for the trigger file and do a move in one go.

Checking for the trigger file through plink or pscp seems to be unnecessarily extra work.  You have to check through linux, then copy to Windows, then delete through linux.  Unless you're restricted to using SSH because of requirements or firewall rules, the other 2 methods using SAMBA are easier to accomplish.