open.itworld.com
  Search  
Security Home Page Security Webcasts Security White Papers Security Newsletters Security News Open Topics Careers ITworld Voices ITwhirled The Security site of ITworld.com

Unix Tip: Using pscp to copy files securely

ITworld.com 09/20/2006

Sandra Henry-Stocker, ITworld.com

Digg!

Send in your Unix questions today! | See additional Unix tips and tricks

Many people who use PuTTY to make secure connections between Windows desktops and Unix servers are unaware that PuTTY also provides a tool for securely moving files between the two platforms. The reason for this oversight is that, while PuTTY provides a terminal-like window on its users desktops, the pscp command (PuTTY's scp command) that PuTTY provides for moving files has to be run from the command line.

If you use PuTTY on a Windows box to connect to your Unix systems, here's what you have to do to use the pscp command. First, you need to open a DOS command prompt. On some versions of Windows, you will find an option for the command prompt in your start menu. On others, the easiest way to get a command prompt is to select Start -> run and then type "cmd" in the text field.

With a DOS prompt window available, you can then issue the pscp command on the command line. If you've customized your Windows environment, adding PuTTY's install directory to your search path, you can just type a command like this:

pscp C:\xfer\myfile.txt user@myserver:/home/user
If you haven't altered your default search path, you can cd to the directory in which pscp is stored (probably C:\Program Files\PuTTY) and issue the command from there.

As you can see, pscp syntax is scp syntax. This command would copy the myfile.txt file from the C: drive to the home directory of "user" on myserver. The "user@" portion of the command allows you to specify the identity of the Unix user whose credentials will be used to accomplish the transfer. The system will prompt you for user's password and will then transfer the file, providing the user has proper permissions for the destination directory.

PuTTY is usually installed in C:\Program Files\PuTTY. To add this directory to your search path on a temporary basis, you can issue this command:
set PATH=C:\Program Files\putty;%PATH%
The %PATH% variable is analogous to $PATH on Unix systems and is appended to the end of this command so that the previously existing contents of the PATH variable are not lost.

To make the change to your path permanent, you would right click on "My Computer" => Properties => Advanced => Environment Variables. At that point, you can make changes to the Path variable.

Of course, you can also use the pscp command to copy files from a Unix system to your Windows box. As with scp, you simply reverse the order in which you specify the files:
pscp user@myserver:/home/user/myfile.txt C:\xfer
The pscp command also has the same options as scp. One of the more useful of these is the recursive option that allows you to copy a group of files with one command. You can also use wildcards. If you have a directory named images and another named more_images that you want to copy from your Windows box to your Unix server, a command like this would recreate both directories complete with their contents on the target system:
pscp -r C:\xfer\*images root@myserver:/opt/apache
After being prompted once for the root password, you would see the contents of both directories being uploaded.

While I'm no Windows geek, I've learned just enough about batch files to automate some repetitive tasks and moving files on a routine basis is a great candidate for automation. I use batch files like the one shown below to download files from one system and upload them to another.
@ECHO OFF
:: Copies files from old to new system
::

:: erase previous files
erase C:\old\*

:: download files to laptop
pscp shs@old:/export/home/shs/2copy/* C:\old

:: upload to new system
pscp C:\old\* shs@new:/home/shs

goto end

:end
Unlike scripts on Unix systems, batch files need to be have the .bat file extension and are invoked by typing the filename without its extension. For example the batch file "movefiles.bat" would be invoked by typing "movefiles". As with the PuTTY command, putting the pathname of your batch files directory into your patch will make it a lot less troublesome to call your scripts.

On this topic

&nsbp;

Sandra Henry-Stocker has been administering Unix systems for more than 18 years. She describes herself as "USL" (Unix as a second language) but remembers enough English to write books and buy groceries. She currently works for TeleCommunication Systems, a wireless communications company, in Annapolis, Maryland, where no one else necessarily shares any of her opinions. She lives with her second family on a small farm on Maryland's Eastern Shore. Send comments and suggestions to bugfarm@gmail.com.




Sponsored Links

Sign up for a Microsoft Dynamics® CRM WEBCAST
Hear globally recognized leaders in customer strategy discuss the importance and evolution of CRM.
Sun Microsystems' - FREE 60 DAY TRIAL OFFER!
Test Sun's Newest Servers BEFORE YOU BUY. Plug Them In With Access To Full Technical Support.
100% Web Based Help Desk Software
Easy to use, customizable to meet your needs, powerful and scalable. Free online demo. Try it today!
Sign up for a Microsoft Dynamics® CRM WEBCAST
Hear globally recognized leaders in customer strategy discuss the importance and evolution of CRM.
Used and Refurbished HP ProCurve Switches
Lifetime Warranties, Professional Testing & Shipping on all HP Equipment Purchases!
» Buy a link now

Advertisements
Sponsored links
Locate Hidden Software on business PCs with this free tool
Bring harmony to your mix of UNIX-Linux-Windows computing environments
Top 5 Reasons to Combine App Performance and Security
KODAK i1400 Series Scanners stand up to the challenge
 Home   Open source  Operating systems  Unix
www.itworld.com    open.itworld.com     security.itworld.com     smallbusiness.itworld.com
storage.itworld.com     utilitycomputing.itworld.com     wireless.itworld.com

 
Contact Us   About Us   Privacy Policy    Terms of Service   Reprints  

CIO   Computerworld   CSO   GamePro   Games.net   IDG Connect   IDG World Expo   Infoworld   ITworld   JavaWorld   LinuxWorld  MacUser   Macworld   Network World   PC World   Playlist  

Copyright © Computerworld, Inc. All rights reserved

Reproduction in whole or in part in any form or medium without express written permission of Computerworld Inc. is prohibited. Computerworld and Computerworld.com and the respective logos are trademarks of International Data Group Inc.