; Kermit FTP script to add ".old" suffix to all files in a server directory.
; 
; Requires C-Kermit 8.0 (Unix) or Kermit 95 2.0 (Windows):
; http://www.columbia.edu/kermit/
;
; F. da Cruz, Columbia University, July 2002
;
; Change these as appropriate or convert them to command-line parameters.
; See: http://www.columbia.edu/kermit/ckscripts.html for an explanation.
;
define user olga                                ; Username
define host ftp.xyzcorp.com                     ; Hostname
define dir  invoices                            ; Remote directory name
define rfs  *                                   ; Remote file specification
define tmp  filelist                            ; Local temp file name

; The rest of the script doesn't need to be changed

ftp \m(host) /user:\m(user)                     ; Open the connection
if fail stop 1 ftp open \m(host) failed         ; Check for failure
ftp cd \m(dir)                                  ; CD to remote directory
if fail stop 1 ftp cd \m(dir) failed            ; Check for failure
ftp mget /namelist:\m(tmp) \m(rfs)              ; Get list of filenames
if fail stop 1 ftp mget /namelist failed        ; Check for failure
fopen /read \%c \m(tmp)                         ; Open the namelist file
if fail stop 1 Open \m(tmp) failed: \f_errmsg() ; Check for failure

.\%n = 0                                        ; Initialize file counter
set flag off                                    ; Error indication
while not flag {                                ; Loop through files
    fread \%c filename                          ; Read next filename
    if fail break                               ; Failure is EOF
    increment \%n                               ; Count the file
    echo \%n. \m(filename)                      ; Give feedback
    ftp rename \m(filename) \m(filename).old    ; Rename this file
    if fail set flag on                         ; Check for failure
}
ftp dir                                         ; Done - Show remote files
ftp bye                                         ; Disconnect from server

if flag stop 1 ftp rename failed: \m(filename)  ; Report any failure
echo Files renamed: \%n                         ; Or report success
end
