pro ksc_commands, qstop=qstop

; Set up the ftp get directory:

file1 = 'cmdlst'
file2 = 'cmplst'
node  = 'flare1'
user  = 'yohkoh' & passwd = 'UchinoUra'
indir = '/home/flare1/sxt/sxtspt/'

; Set up the output directory name:

outdir0='/home/sxt_co/KSC_commands/'

message,/info,'Will write data to: '+outdir0

; Make sure the output directory exists:

if not file_exist(outdir0) then begin
  message,/info,'Creating output directory: '+outdir0
  spawn,'mkdir '+outdir0
  if not file_exist(outdir0) then $
         message,'Error -- Could not create output directory'
endif

rawdir = outdir0        ; Return the output directory
home_dir = curdir()     ; Save the current possition
cd,outdir0


; Generate output filenames

arrmo=month_cnv(indgen(12)+1,/short)
ftp_copy,file1,node,user,passwd,indir,dirlist=dirlist,/list
str2=strcompress(dirlist(0))
arr2=str2arr(str2,' ')
jmonth=where(arrmo eq arr2(5)) 
imonth=fix(jmonth(0))+1
cmonth=string(imonth,format='(i2.2)')
tpresent=anytim2ints(!stime)
epresent=anytim2ex(tpresent)
ypresent=epresent(6)
mpresent=epresent(5)
if mpresent lt imonth then ypresent=ypresent+99
if ypresent le 91 then ypresent=ypresent+2000 else ypresent=ypresent+1900

yyyy=string(ypresent,format='(i4.4)')
mo=cmonth
dd=string(fix(arr2(6)),format='(i2.2)')
hh=strmid(arr2(7),0,2)
mn=strmid(arr2(7),3,2)
outname1=file1+'.'+yyyy+mo+dd+'.'+hh+mn

; blah=anytim(!stime,/ccsds)
; yyyy=strmid(blah,0,4)
; mo=strmid(blah,5,2)
; dd=strmid(blah,8,2)
; hh=strmid(blah,11,2)
; mn=strmid(blah,14,2)

str2=strcompress(dirlist(1))
arr2=str2arr(str2,' ')
jmonth=where(arrmo eq arr2(5)) 
imonth=fix(jmonth(0))+1
cmonth=string(imonth,format='(i2.2)')
tpresent=anytim2ints(!stime)
epresent=anytim2ex(tpresent)
ypresent=epresent(6)
mpresent=epresent(5)
if mpresent lt imonth then ypresent=ypresent+99
if ypresent le 91 then ypresent=ypresent+2000 else ypresent=ypresent+1900

yyyy=string(ypresent,format='(i4.4)')
mo=cmonth
dd=string(fix(arr2(6)),format='(i2.2)')
hh=strmid(arr2(7),0,2)
mn=strmid(arr2(7),3,2)
outname2=file2+'.'+yyyy+mo+dd+'.'+hh+mn

;FIRST FILE
; Spawn the ftp command:

ftp_copy,file1,node,user,passwd,indir,/get,/ascii,ftp_res=ftp_res,outfil=outname1

; Should add a OUTFILE to this in order to change the name of the 
; output, including the date+time of the ftp....DMcK

print,ftp_res       ; Report the ftp status

; Do a find file on the new files:

new_files = findfile(outname1,count=count)
if count eq 0 then print,'No files copied' else begin
  print,'Number of files copied = ',strtrim(count,2)
  print,new_files,format='(6(2x,a))'
endelse

; SECOND FILE

ftp_copy,file2,node,user,passwd,indir,/get,/ascii,ftp_res=ftp_res,outfil=outname2
print,ftp_res       ; Report the ftp status
new_files = findfile(outname2,count=count)
if count eq 0 then print,'No files copied' else begin
  print,'Number of files copied = ',strtrim(count,2)
  print,new_files,format='(6(2x,a))'
endelse

; Return to the original directory:
 
cd,home_dir

if keyword_set(qstop) then stop
end