Shortcut batch files that works with Putty
Putty is one of the most common software with which people work on remote machines, which typically has a UNIX/Linux system for stability or efficiency reasons.
To operate on the remote machine, I think the reader should be familiar with the pageant program. Type in your remote host IP (e.g. “192.168.x.x”) or host name (e.g. “super-computer-1”) at the proper blank, and clicking the “Open” button will get you there. Next just enter your user-name and password on that computer and you’ll get a bash interface to work on.
But transferring files between the remote computer and your local PC is a bit complicated. You’ll need to use the command-line program pscp to communicate with the remote computer, which probably is short for “Putty Secure Copy”. This post is mainly about using this program.
I have two batch files in my putty directory, called “get.bat” and “send.bat”, respectively. They look something like:
pscp -v USERNAME@REMOTE_SERVER:/home/USERNAME/%1 LOCAL_FOLDER\%2 < PASSWORD
pscp -v LOCAL_FOLDER\%1 USERNAME@REMOTE_SERVER:/home/USERNAME/%2 < PASSWORD
These are nothing difficult to understand. LOCAL_FOLDER is the local folder you often work with (my personal habit is to put all my programs in sub-directories of such a folder). USERNAME is your user-name on the remote computer REMOTE_SERVER. As with pageant, REMOTE_SERVER can both be remote IP or remote machine name. PASSWORD, acturally, is a file containing the first line your remote server password and the second line nothing (in fact what matters is the return at the end of the first line). using < PASSWORD allows you to use the file PASSWORD as the input to the console whenever your password (followed by a return) is needed by pscp.
By the way, the switch -v stands for verbose, which allows pscp to print the detailed progress of connection, file transfer, etc. I prefer it’s on. Another switch that may come handy is the -r switch, which allows pscp to recursively copy all sub-directories and all files in them of the given directory, from one computer to another.
Now with these preparations done, all you need to do is cd to your Putty directory, and type
send my_local_program/* my_remote_folder rem Remark: Do something (like run your program) on your remote computer here get my_remote_folder/result/* my_local_program/result/ rem Remark: Make sure the folders exist on both side, or pscp might fail
blog comments powered by Disqus