University of Colorado at Boulder    
Map A to Z Index Search CU Home
ITS logo
Information Technology Services News | ITS Search
ITS Docs
  Using Scripts or Batch files with SSH Secure Shell 3.2.0
 

To create an automated upload or download sequence with SFTP you will first have to create a Keypair that will be responsible for the authentication process of the sequence. Once the keys have been created and placed in the appropriate location on the client machine and the server, the SFTP client will be able to authenticate and transfer files using a script.

Step 1: Creating Keypairs

1. Open an SSH or SFTP session to the host using the SSH Secure Shell GUI.

2. Select Edit -> Settings

3. Under Global Settings -> User Authentication -> Keys, Click Generate New

4. In the Key Generation Wizard click Next

5. The Key Type should be DSA and the Key Length should be 2048.

6.Click Next and wizard will generate public and private keys.

7. When this process is complete, click Next

8. Enter a file name for your key (Do not enter anything for Comment or Passphrase). Click Next.

9. Click Yes in the window warning "you have entered an empty passphrase"

10. Click Upload Public Key

11. Accept the defaults for Uploading Public Key and click Upload (It will create a folder called .ssh2 at the root of your home dir to store the public key)

12. Click the Finish button.

13. Click Ok on the settings window.

To verify that the keys are working, disconnect from the server and reconnect. (If you didn't create a profile to the server, when you choose "Quick Connect" you will need to change the authentication method to "Public Key". Your client should login using the public and private keys, bypassing your password.

Note: Because your private key is not protected with a passphrase it is important that the key reside in a secured directory on you local machine.

Step 2: Creating the SSH script and batch files (example)

1. Create a directory on spot (or your server) called test

2. Create a directory on your local machine called C:\ssh2test

3. Create a file called test.txt in C:\ssh2test\
Put anything you want in the file

4. Create a file called up.txt in C:\ssh2test\

5. Put the following lines in up.txt

open username@spot.colorado.edu
binary
cd test
put test.txt
quit

6. Create a bat file called go.bat in C:\ssh2test\

7. Put the following line in go.bat

sftp2 -B up.txt

8. Now run go (from the command prompt). You should see an output like the following.

C:\ssh2test>go
C:\ssh2test>sftp2 -B up.txt

sftp> open username@spot.colorado.edu
Opening connection to username@spot.colorado.edu
sftp> binary
File transfer mode is now binary
sftp> cd test
/home/username/test
sftp> put test3.txt
test3.txt | 0 kB | 0.1 kB/s | TOC: 00:00:01 | 100%
sftp> quit

C:\ssh2test>

The ftp script commands you want to run should be placed in up.txt

The "-B" flag allows you to specify a scripted file for sftp.
Note: sftp2.exe -B does not accept a cleartext password or a passphrase to be present in the script file. You must use keypairs without a passphrase.

Get Help

To get help contact the IT Service Center by phone at 303-735-HELP (5-4357 from an on-campus phone), by e-mail at help@colorado.edu, or in person at the IT Service Center walk-in (located two buildings east of the UMC).

Encrypted Authentication Project

Encrypted Authentication Project homepage

 

 

Search by Topic

 

Did this document help you?
yes    no

How can it be improved?

       
       Support | Training | Facilities | About ITS | ITS Home
 

Last reviewed: April 08, 2005

itsfeedback@colorado.edu  | Policies | Privacy
© 2000
The Regents of the University of Colorado