Most recent update: Tue Apr 16 17:19:26 2002
[ C-Kermit ] [ C-Kermit Tutorial ] [ Kermit Scripts ] [ Kermit Home ]
Now that SSH connections are replacing Telnet and FTP at many sites, we frequently hear complaints about SFTP (and SCP), the main ones being:
Now with C-Kermit and Kermit 95, you can make Kermit client/server connections over SSH, thus combining the best of both worlds: SSH security plus Kermit's capabilities:
Each of these points is elaborated at some length at the Kermit website.
On the host, install the C-Kermit 8.0 binary in the normal way. Then, in the same directory as the C-Kermit binary, make a symbolic link:
ln -s kermit kermit-sshsub
Then in the sshd configuration file, add a line:
Subsystem kermit /some/path/kermit-sshsub
(where /some/path is the fully specified directory where the symlink is.) This is similar to the line that sets up the SFTP susbsystem. Example:
Subsystem sftp /usr/local/libexec/sftp-server Subsystem kermit /usr/local/bin/kermit-sshsub
The mechanics might vary for other SSH servers; "man sshd" for details. The method shown here is used because the OpenSSH server does not permit the subsystem invocation to include command-line options. C-Kermit would have no way of knowing that it should enter Server mode if it were not called by a special name.
[ K95 Home ] [ C-Kermit Home ] [ OpenSSH Home ] [ Kermit Home ] [ C-Kermit Daily Updates ]
Kermit 95 1.1.21 and later have an SSH client built in, so making SSH connections to the Kermit subsystem is perfectly straightforward:
set host [ /user:username ] /network:ssh hostname /subsystem:kermit
You can omit the /USER: switch if your local and remote usernames are the same. If a password is required, you are prompted locally (or you can supply it in the SET HOST command; see the K95 SSH Client documentation for details). If the SET HOST command succeeds, you have a Kermit client/server connection over an SSH transport. At the K-95> prompt (or in a Kermit 95 script program) you can issue all the same commands you would normally use with a Kermit server: SEND, GET, REMOTE DIRECTORY, REMOTE DELETE, and so on. BYE or FINISH terminates the connection.
[ K95 Home ] [ K95 Tutorial ] [ K95 SSH Client ]
Since C-Kermit does not have SSH built in, it must use an external ssh client as the connection agent and transport. This is done through pipes, a capability that was added in C-Kermit 7.0 (January 2000). Conceptually it could also be done with pseudoterminals, but in practice there are some logistical roadblocks on each end.
NOTE: C-Kermit 8.0 has an SSH command, which makes a terminal connection to an SSH host. This is not the same thing as a client/server connection. C-Kermit's SSH command can NOT be used to access an SSH Kermit subsystem.
Since we are using external ssh client software, and since there are different ssh clients (and different releases of each one), the exact command to be used to make an SSH/Kermit connection can vary. Here is the command for the OpenSSH 3.0.2p1 client:
set host /pipe ssh -e none [ -l username ] -T -s hostname kermit
Example:
set host /pipe ssh -e none -l olga -T -s hq.xyzcorp.com kermit
The SSH client might or might not prompt you for a password or other information before it makes the connection; this depends on your SSH configuration (your public and private keys, your authorized hosts file, etc). Here's a brief synopsis of the OpenSSH client command syntax ("man ssh" for details):
You might want to include other or additional ssh command-line options; "man ssh" explains what they are. Here are some examples for the OpenSSH 3.0.2p1 client:
[ C-Kermit Home ] [ C-Kermit Tutorial ] [ OpenSSH Home ]
Once you have an SSH connection to a Kermit server, it's just like any other connection to a Kermit server (and very similar to a connection to an FTP server). You give the client file transfer and management commands for the server, and the server executes them. Of course you can also give the client any other commands you wish. For a quick introduction to Kermit client commands, see:
Let's look at the basics of SSH script construction. We'll start with Unix simply because it's more script-friendly, and also because scripts are needed in Unix anyway to adapt to different SSH clients (OpenSSH, Data Fellows, Solaris, ...)
Let's dive right in with a simple script that uses the SSH 3.0.2p1 client as its connection agent to make an interactive client/server connection. The following script works with any version of C-Kermit 7.0 or later:
#!/usr/local/bin/kermit + # # skermit -- SSH connection to Kermit server subsystem # Assumes OpenSSH 3.0.2p1 client. # # Command-line arguments: # 1 = host # 2 = user (optional, defaults to local username) # if not def \%1 exit 1 Usage: \%0 host [ user ] if not def \%2 .\%2 := \v(user) set exit warning off set host /pipe ssh -e none -l \%2 -T -s \%1 kermit if fail exit 1 set reliable on if echo You might have to wait for a password prompt here... set input echo on input 60 KERMIT READY TO SERVE... .\%9 := \v(status) echo if \%9 exit 1 Kermit Server not found set input echo off echo echo You have a Kermit server on the other end of the connection. echo Use the following commands: SEND, GET, RCD, RPWD, RDIR, ... echo Close the connection with BYE or FINISH. echo
Save the script somewhere in your PATH, call it "skermit", and give it execute permission:
chmod +x skermit
Now you can invoke the script in any of three ways:
Now let's look at the script line by line:
The remaining ECHO statements just print some simple instructions.
Now let's pay closer attention to the SET HOST command that starts the ssh client:
set host /pipe ssh -e none -l \%2 -T -s \%1 kermit
As explained in the C-Kermit 7.0 documentation, SET HOST /PIPE makes a "network" connection, but instead of to a true network like the Internet, it makes it to an external program through a pair of pipes -- one for input, one for output. Unlike the PIPE command itself, SET HOST /PIPE does not include an implied CONNECT command. We use SET HOST /PIPE instead of PIPE because we are not making a terminal connection (if we did, it would only connect us to the server's packet reader).
C-Kermit also has another way of controlling subprograms such as ssh: the SET HOST /PTY command, but we don't use it in this case simply because it doesn't work.
After SET HOST /PIPE comes the ssh invocation itself:
ssh -e none -l \%2 -T -s \%1 kermit
which happens to apply to the OpenSSH 3.0.2p1 client; the options are explained in "man ssh".
[ C-Kermit Scripts ] [ C-Kermit 7.0 Documentation ] [ C-Kermit 8.0 Documentation ]
In Windows, if you save a Kermit script file with a suffix of .KSC, this associates it with Kermit 95. Clicking on any file named this way causes Kermit 95 to start and execute commands from the file. But unfortunately, there is no way to pass parameters to a script when you invoke it in this way. But you can pass parameters if you invoke it from a command window, or from within Kermit 95 itself. Thus the first adaptation is to make the script prompt for (or supply) any missing parameters:
while not def \%1 { ask \%1 { Host: } } if < \v(argc) 2 { ask \%2 { User [\v(user)] } } if not def \%2 .\%2 := \v(user)
If the first command-line parameter, \%1 (the hostname) is missing, we prompt for it until it is given. Then, only if a hostname was not given on the command line, we prompt for a username. Then if there still is no username, we supply the local username. This allows for all possible invocations:
The second adaptation allows for the different commands that must be used to make SSH connections in C-Kermit and Kermit 95. The key commands for adaptations like this are:
Here we execute the appropriate connection command:
if k-95 { set host /network:ssh /user:\%2 \%1 /subsystem:kermit } else { set host /pipe ssh -e none -l \%2 -T -s \%1 kermit }
And here we print the "You might have to wait" message only if it's not Kermit 95:
if not k-95 echo You might have to wait for a password prompt here...
This could also have been written as:
if c-kermit echo You might have to wait for a password prompt here...
Now the same script can be used in Unix and Windows. Here is the portable version of the script in full:
#!/usr/local/bin/kermit + # # skermit -- SSH connection to Kermit server subsystem # Assumes OpenSSH 3.0.2p1 client. # # Command-line arguments: # 1 = host # 2 = user (optional, defaults to local username) # while not def \%1 { ask \%1 { Host: } } if < \v(argc) 2 { ask \%2 { User [\v(user)] } } if not def \%2 .\%2 := \v(user) set exit warning off if k-95 { set host /network:ssh /user:\%2 \%1 /subsystem:kermit } else { set host /pipe ssh -e none -l \%2 -T -s \%1 kermit } if fail exit 1 set reliable on if not k-95 echo You might have to wait for a password prompt here... set input echo on input 60 KERMIT READY TO SERVE... .\%9 := \v(status) echo if \%9 exit 1 Kermit Server not found set input echo off echo echo You have a Kermit server on the other end of the connection. echo Use the following commands: SEND, GET, RCD, RPWD, RDIR, ... echo Close the connection with BYE or FINISH. echo
The simple "skermit" script shown above gives you the connection but leaves the rest to you. Obviously the script could be extended to do whatever else you want:
Just replace the block of ECHO commands at the end with whatever other commands you want. Here's an example in which fetch one file and quit. First we add a WHILE command to check for a third command-line parameter:
while not def \%3 { ask \%3 { File to Get: } }
Then at the end, we put the commands to get the file, disconnect, and exit:
get \%3 bye exit
In which:
Here's a slightly more ambitious example. Suppose every time you run this script, you want to CD to certain remote and local directories and refresh the local directory with any new files from the remote one:
define serverdir /usr/olga/orders/ define localdir c:/olaf/orders/ rcd \m(serverdir) if fail exit 1 Server directory \m(serverdir) not found cd \m(localdir) if fail exit 1 Failure to CD to client directory \m(localdir) set file collision update get * bye exit
Let's step through this line by line:
Build on these examples. The sky is the limit. Begin by visiting the Kermit scripting tutorial at the website.
[ Top ] [ Contents ] [ K95 Home ] [ C-Kermit Home ] [ C-Kermit Scripting ] [ Kermit Home ]