ftpdemo.tcl
Go to the documentation of this file.00001
00002
00003 exec tclsh "$0" ${1+"$@"}
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 package require Tcl 8.3
00026 package require Tk
00027 package require ftp 2.0
00028
00029
00030 if { [string range [winfo server .] 0 0] == "X" } {
00031 option add *background LightGray
00032 tk_Palette = LightGray
00033 option add *Text.foreground black
00034 option add *Text.background [option get . selectBackground Listbox]
00035 option add *Listbox.background [option get . selectBackground Listbox]
00036 option add *Listbox.selectBackground [option get . insertBackground Listbox]
00037 option add *Listbox.selectForeground white
00038 option add *Entry.background [option get . selectBackground Listbox]
00039 option add *Entry.selectBackground [option get . insertBackground Listbox]
00040 option add *Entry.selectForeground white
00041 option add *borderWidth 2
00042 } else {
00043 option add *Checkbutton.borderWidth 0
00044 option add *Radiobutton.borderWidth 0
00045
00046 }
00047
00048
00049 wm title . "ftp Test"
00050 wm iconname . ftptest
00051 wm minsize . 1 1
00052
00053
00054 frame .msg -bd 1 -relief raised
00055 pack .msg -in . -side top -fill both -expand 1
00056 frame .op -bd 1 -relief raised
00057 pack .op -in . -side top -fill x
00058 frame .but -bd 1 -relief raised
00059 pack .but -in . -side top -fill both -expand 1
00060
00061
00062
00063
00064
00065 frame .op.f -bd 3
00066 pack .op.f -in .op -side top -fill x
00067
00068
00069 frame .op.f.f1 -bd 3
00070 pack .op.f.f1 -in .op.f -side left -fill both
00071 label .op.f.f1.l -bd 2 -text "Server Options: " -relief flat -anchor w
00072 pack .op.f.f1.l -in .op.f.f1 -side top -fill x
00073
00074 frame .op.f.f1.server -bd 2
00075 pack .op.f.f1.server -in .op.f.f1 -side top -fill x -padx 15
00076 label .op.f.f1.server.l -text "Host: " -width 10 -relief flat -anchor w
00077 pack .op.f.f1.server.l -in .op.f.f1.server -side left -fill x
00078 entry .op.f.f1.server.e -width 20
00079 pack .op.f.f1.server.e -in .op.f.f1.server -side left -fill x
00080
00081 frame .op.f.f1.port -bd 2
00082 pack .op.f.f1.port -in .op.f.f1 -side top -fill x -padx 15
00083 label .op.f.f1.port.l -text "Port: " -width 10 -relief flat -anchor w
00084 pack .op.f.f1.port.l -in .op.f.f1.port -side left -fill x
00085 entry .op.f.f1.port.e -width 5
00086 pack .op.f.f1.port.e -in .op.f.f1.port -side left -fill x
00087
00088 frame .op.f.f1.username -bd 2
00089 pack .op.f.f1.username -in .op.f.f1 -side top -fill x -padx 15
00090 label .op.f.f1.username.l -text "Username: " -width 10 -relief flat -anchor w
00091 pack .op.f.f1.username.l -in .op.f.f1.username -side left -fill x
00092 entry .op.f.f1.username.e -width 10
00093 pack .op.f.f1.username.e -in .op.f.f1.username -side left -fill x
00094
00095 frame .op.f.f1.password -bd 2
00096 pack .op.f.f1.password -in .op.f.f1 -side top -fill x -padx 15
00097 label .op.f.f1.password.l -text "Password: " -width 10 -relief flat -anchor w
00098 pack .op.f.f1.password.l -in .op.f.f1.password -side left -fill x
00099 entry .op.f.f1.password.e -width 10 -show "*"
00100 pack .op.f.f1.password.e -in .op.f.f1.password -side left -fill x
00101
00102 frame .op.f.f1.directory -bd 2
00103 pack .op.f.f1.directory -in .op.f.f1 -side top -fill x -padx 15
00104 label .op.f.f1.directory.l -text "Directory: " -width 10 -relief flat -anchor w
00105 pack .op.f.f1.directory.l -in .op.f.f1.directory -side left -fill x
00106 entry .op.f.f1.directory.e -width 20
00107 pack .op.f.f1.directory.e -in .op.f.f1.directory -side left -fill x
00108
00109
00110 frame .op.f.sep1 -bd 1 -relief sunken
00111 pack .op.f.sep1 -in .op.f -fill y -side left -pady 2 -padx 4
00112 frame .op.f.sep1.f -bd 1 -relief flat
00113 pack .op.f.sep1.f -in .op.f.sep1 -fill y -side left
00114
00115 frame .op.f.f2 -bd 3
00116 pack .op.f.f2 -in .op.f -side left -fill both -ipadx 15
00117
00118 label .op.f.f2.l2 -borderwidth 2 -anchor w -text "Transfer mode:"
00119 pack .op.f.f2.l2 -in .op.f.f2 -side top -fill x
00120 radiobutton .op.f.f2.active -anchor w -text "Active" -variable test(mode) -value "active"
00121 pack .op.f.f2.active -in .op.f.f2 -side top -fill x -padx 15
00122 radiobutton .op.f.f2.passive -anchor w -text "Passive" -variable test(mode) -value "passive"
00123 pack .op.f.f2.passive -in .op.f.f2 -side top -fill x -padx 15
00124
00125
00126
00127
00128
00129 label .op.f.f2.l1 -borderwidth 2 -anchor w -text "Debugging:"
00130 pack .op.f.f2.l1 -in .op.f.f2 -side top -fill x
00131 checkbutton .op.f.f2.debug -anchor w -text "Debug" -variable ftp::DEBUG
00132 pack .op.f.f2.debug -in .op.f.f2 -side top -fill x -padx 15
00133 checkbutton .op.f.f2.verbose -anchor w -text "Verbose" -variable ftp::VERBOSE
00134 pack .op.f.f2.verbose -in .op.f.f2 -side top -fill x -padx 15
00135
00136
00137 frame .op.f.f2.loops -bd 2
00138 pack .op.f.f2.loops -in .op.f.f2 -side top -fill x -pady 2
00139 label .op.f.f2.loops.l -borderwidth 2 -text "Iterations: " -relief flat -anchor w
00140 pack .op.f.f2.loops.l -in .op.f.f2.loops -side left -fill x
00141 entry .op.f.f2.loops.e -borderwidth 2 -width 5
00142 pack .op.f.f2.loops.e -in .op.f.f2.loops -side left -fill x
00143
00144
00145 frame .op.f.sep2 -bd 1 -relief sunken
00146 pack .op.f.sep2 -in .op.f -fill y -side left -pady 2 -padx 4
00147 frame .op.f.sep2.f -bd 1 -relief flat
00148 pack .op.f.sep2.f -in .op.f.sep2 -fill y -side left
00149
00150
00151
00152
00153 frame .op.f.f3 -bd 3
00154 pack .op.f.f3 -in .op.f -side left -fill both -expand 1 -ipadx 15
00155
00156 label .op.f.f3.l1 -anchor w -width 10 -text "Variable trace:"
00157 pack .op.f.f3.l1 -in .op.f.f3 -side top -fill x
00158
00159 frame .op.f.f3.v0 -bd 0
00160 pack .op.f.f3.v0 -in .op.f.f3 -side top -fill x -pady 2 -padx 15
00161 label .op.f.f3.v0.name -anchor w -text "iterations = "
00162 pack .op.f.f3.v0.name -in .op.f.f3.v0 -side left -fill x
00163 label .op.f.f3.v0.value -anchor w -textvariable test(loop)
00164 pack .op.f.f3.v0.value -in .op.f.f3.v0 -side top -fill x
00165 frame .op.f.f3.v1 -bd 0
00166 pack .op.f.f3.v1 -in .op.f.f3 -side top -fill x -pady 2 -padx 15
00167 label .op.f.f3.v1.name -anchor w -text "errors = "
00168 pack .op.f.f3.v1.name -in .op.f.f3.v1 -side left -fill x
00169 label .op.f.f3.v1.value -anchor w -textvariable test(errors)
00170 pack .op.f.f3.v1.value -in .op.f.f3.v1 -side top -fill x
00171 frame .op.f.f3.v2 -bd 0
00172 pack .op.f.f3.v2 -in .op.f.f3 -side top -fill x -pady 2 -padx 15
00173 label .op.f.f3.v2.name -anchor w -text "after queues = "
00174 pack .op.f.f3.v2.name -in .op.f.f3.v2 -side left -fill x
00175 label .op.f.f3.v2.value -anchor w -textvariable test(after)
00176 pack .op.f.f3.v2.value -in .op.f.f3.v2 -side top -fill x
00177 frame .op.f.f3.v4 -bd 0
00178 pack .op.f.f3.v4 -in .op.f.f3 -side top -fill x -pady 2 -padx 15
00179 label .op.f.f3.v4.name -anchor w -text "open channels:"
00180 pack .op.f.f3.v4.name -in .op.f.f3.v4 -side top -fill x
00181 label .op.f.f3.v4.value -anchor w -textvariable test(open)
00182 pack .op.f.f3.v4.value -in .op.f.f3.v4 -side top -fill x -padx 8
00183
00184
00185
00186 frame .msg.f -bd 3
00187 pack .msg.f -in .msg -side top -fill both -expand 1
00188
00189 frame .msg.f.f1 -bd 2 -relief groove
00190 pack .msg.f.f1 -in .msg.f -side left -fill both -padx 2 -pady 2
00191 label .msg.f.f1.l -text "Test commands: " -relief flat -anchor w
00192 pack .msg.f.f1.l -in .msg.f.f1 -side top -fill x -padx 4 -pady 2
00193
00194
00195 idlist = {}
00196 foreach {id text} { quote "System Info"\
00197 list "List" \
00198 nlist "NList" \
00199 dir "Cd, MkDir, RmDir" \
00200 afile "ASCII Put/Get" \
00201 bfile "Binary Put/Ret" \
00202 ren "Rename" \
00203 append "Append" \
00204 new "Newer" \
00205 reget "Reget" \
00206 notfound "file not found"} {
00207 checkbutton .msg.f.f1.$id -anchor w -text $text -variable test($id)
00208 pack .msg.f.f1.$id -in .msg.f.f1 -side top -fill x -padx 16
00209 test = ($id) 1
00210 lappend idlist $id
00211 }
00212 button .msg.f.f1.plus -text "+ all" -command "foreach i {$idlist} { test = (\$i) 1}"
00213 pack .msg.f.f1.plus -in .msg.f.f1 -side left -fill x -padx 16 -pady 8
00214 button .msg.f.f1.minus -text "- all" -command "foreach i {$idlist} { test = (\$i) 0}"
00215 pack .msg.f.f1.minus -in .msg.f.f1 -side left -fill x -pady 8
00216
00217 frame .msg.f.f2 -bd 2 -relief groove
00218 pack .msg.f.f2 -in .msg.f -side left -fill both -pady 2
00219
00220 label .msg.f.f2.label -text "Messages:" -anchor w
00221 pack .msg.f.f2.label -in .msg.f.f2 -side top -fill x -padx 2
00222 scrollbar .msg.f.f2.yscroll -command ".msg.f.f2.text yview"
00223 pack .msg.f.f2.yscroll -in .msg.f.f2 -side right -fill y
00224 scrollbar .msg.f.f2.xscroll -relief sunken -orient horizontal -command ".msg.f.f2.text xview"
00225 pack .msg.f.f2.xscroll -in .msg.f.f2 -side bottom -fill x
00226 text .msg.f.f2.text -relief sunken -grid = 1 -wrap none -height 20 -width 80 -bg white -fg black\
00227 -state disabled -xscrollcommand ".msg.f.f2.xscroll " \
00228 -yscrollcommand = ".msg.f.f2.yscroll "
00229 pack = .msg.f.f2.text -in .msg.f.f2 -side left -expand 1 -fill both
00230 .msg.f.f2.text tag configure error -foreground red
00231 .msg.f.f2.text tag configure data -foreground brown
00232 .msg.f.f2.text tag configure control -foreground blue
00233 .msg.f.f2.text tag configure header -foreground white -background black
00234
00235
00236
00237 frame .but.f -bd 3
00238 pack .but.f -in .but -side top -fill both -expand 1
00239
00240 frame .but.f.f1 -bd 3
00241 pack .but.f.f1 -in .but.f -side top -fill x -padx 15 -pady 6
00242 button .but.f.f1.start -text "Start Test" -width 12 -state normal -command "StartTest"
00243 pack .but.f.f1.start -side left -fill x -padx 15
00244 button .but.f.f1.stop -text "Stop Test" -width 12 -state disabled -command "StopTest"
00245 pack .but.f.f1.stop -side left -fill x -padx 15
00246 button .but.f.f1.close -text "Quit" -width 12 -state normal -command "destroy ."
00247 pack .but.f.f1.close -side right -fill x -padx 15
00248 button .but.f.f1.save -text "Save Options" -width 12 -state normal -command "SaveConfig"
00249 pack .but.f.f1.save -side right -fill x -padx 15
00250
00251
00252
00253
00254 namespace ftp {
00255 ret DisplayMsg (type s , type msg , optional state ="") {
00256 global test
00257 .msg.f.f2.text configure -state normal
00258
00259 # change state from "error" to "" for procedure test_9notfound
00260 if { ($state == "error") && [info exist test(proc)] && ($test(proc) == "test_99notfound") } {
00261 set state ""
00262 }
00263
00264 switch -exact -- $state {
00265 data {.msg.f.f2.text insert end "$msg\n" data}
00266 control {.msg.f.f2.text insert end "$msg\n" control}
00267 error {.msg.f.f2.text insert end "$msg\n" error; incr test(errors)}
00268 header {.msg.f.f2.text insert end "$msg\n" header}
00269 default {.msg.f.f2.text insert end "$msg\n"}
00270 }
00271 .msg.f.f2.text configure -state disabled
00272 .msg.f.f2.text see end
00273 update idletasks
00274 }}
00275
00276
00277 rename open ftpopen
00278 ret open (type args) {
00279 global test
00280 set rc [eval ftpopen $args]
00281 if {[lsearch -exact $test(open) $rc] == "-1"} {
00282 lappend test(open) $rc
00283 }
00284 #puts "open: $test(open)"
00285 return $rc
00286 }
00287
00288
00289 rename close ftpclose
00290 ret close (type args) {
00291 global test
00292 set rc [eval ftpclose $args]
00293 set index [lsearch -exact $test(open) $args]
00294 if {$index != "-1"} {
00295 set test(open) [lreplace $test(open) $index $index]
00296 }
00297 #puts "close: $test(open)"
00298 return $rc
00299 }
00300
00301
00302 rename socket ftpsocket
00303 ret socket (type args) {
00304 global test
00305 set rc [eval ftpsocket $args]
00306 if {[lsearch -exact $test(open) $rc] == "-1"} {
00307 lappend test(open) $rc
00308 }
00309 #puts "socket: $test(open)"
00310 return $rc
00311 }
00312
00313
00314
00315 namespace ftp {
00316 rename InitDataConn ftpInitDataConn
00317 ret InitDataConn (type args) {
00318 global test
00319 set rc [eval ftpInitDataConn $args]
00320 set s [lindex $args 0]
00321 if {[lsearch -exact $test(open) $s] == "-1"} {
00322 lappend test(open) $s
00323 }
00324 #puts "InitDataConn: $test(open)"
00325 return $rc
00326 }}
00327
00328
00329 ret ProgressBar (type state , optional bytes =0 , optional total ={) {filename {}}} {
00330 global progress
00331 w = .progress
00332 switch -exact -- $state {
00333 init {
00334 progress = (percent) "0%"
00335 progress = (total) $total
00336 progress = (left) 0
00337 toplevel $w -bd 0 -class Progressbar
00338 wm transient $w .
00339 wm title $w Progress
00340 wm iconname $w Progress
00341 wm resizable $w 0 0
00342 focus $w
00343
00344 frame $w.frame -bd 4
00345 pack $w.frame -side top -fill both
00346 label $w.frame.label -text "Transfering $filename..." -relief flat -anchor w -bd 1
00347 pack $w.frame.label -in $w.frame -side top -fill x -padx 10 -pady 5
00348 frame $w.frame.bar -bd 1 -relief sunken -bg
00349 pack $w.frame.bar -in $w.frame -side left -padx 10 -pady 5
00350 frame $w.frame.bar.dummy -bd 0 -width 250 -height 0
00351 pack $w.frame.bar.dummy -in $w.frame.bar -side top -fill x
00352 frame $w.frame.bar.pbar -bd 0 -width 0 -height 20
00353 pack $w.frame.bar.pbar -in $w.frame.bar -side left
00354 label $w.frame.proz -textvariable progress(percent) -width 5 -relief flat -anchor e -bd 1
00355 pack $w.frame.proz -in $w.frame -side right -padx 10 -pady 5
00356
00357 wm withdraw $w
00358 update idletasks
00359 x = [expr {[winfo x .] + ([winfo width .] / 2) - ([winfo reqwidth $w] / 2)}]
00360 y = [expr {[winfo y .] + ([winfo height .] / 2) - ([winfo reqheight $w] / 2)}]
00361 wm geometry $w +$x+$y
00362 update idletasks
00363 wm deiconify $w
00364 update idletasks
00365 }
00366
00367 update {
00368 if {![winfo exist $w]} {return}
00369 cur = _width 250
00370 catch {
00371 progress = (percent) "[expr {round($bytes) * 100 / $progress(total)}]%";
00372 cur = _width [expr {round($bytes * 250 / $progress(total))}]
00373 } msg
00374 $w.frame.bar.pbar configure -width $cur_width -bg
00375 update idletasks
00376 }
00377
00378 done {
00379 un progress =
00380 destroy $w
00381 update
00382 }
00383 default {
00384 error "Unknown state \"$state\""
00385 }
00386 }
00387 }
00388
00389
00390
00391
00392 ret test_10list (type loop) {
00393 global test
00394
00395 # check if enabled
00396 if {!$test(list)} {return}
00397
00398 ftp::DisplayMsg $test(conn) "*** TEST $loop.1 (long directory listing) ***" header
00399 set remote_list [ftp::List $test(conn)]
00400 ftp::DisplayMsg $test(conn) "[llength $remote_list] directory lines!"
00401 }
00402
00403
00404
00405
00406 ret test_20nlist (type loop) {
00407 global test
00408
00409 # check if enabled
00410 if {!$test(nlist)} {return}
00411
00412 ftp::DisplayMsg $test(conn) "*** TEST $loop.2 (short directory listing) ***" header
00413 set remote_list [ftp::NList $test(conn)]
00414 ftp::DisplayMsg $test(conn) "[llength $remote_list] directory entries!"
00415 }
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425 ret test_30dir (type loop) {
00426 global test
00427
00428 # check if enabled
00429 if {!$test(dir)} {return}
00430 ftp::DisplayMsg $test(conn) "*** TEST $loop.3 (directory commands cd,mkdir,rmdir) ***" header
00431 ftp::Pwd $test(conn)
00432 ftp::MkDir $test(conn) foo$test(pid)
00433 ftp::Cd $test(conn) foo$test(pid)
00434 ftp::Pwd $test(conn)
00435 ftp::Cd $test(conn) ..
00436 ftp::Pwd $test(conn)
00437 ftp::RmDir $test(conn) foo$test(pid)
00438 }
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450 ret test_40afile (type loop) {
00451 global test
00452
00453 # check if enabled
00454 if {!$test(afile)} {return}
00455
00456 ftp::DisplayMsg $test(conn) "*** TEST $loop.4 (put/get ascii files) ***" header
00457 set ascii_file ftpdemo.tcl
00458 set lsize [file size $ascii_file]
00459 ftp::Type $test(conn) ascii
00460 ftp::Put $test(conn) $ascii_file ignore$test(pid).tmp
00461
00462 # FileSize only works proper in binary mode
00463 ftp::Type $test(conn) binary
00464 set rsize [ftp::FileSize $test(conn) ignore$test(pid).tmp]
00465 ftp::Type $test(conn) ascii
00466 ftp::Get $test(conn) ignore$test(pid).tmp
00467 ftp::Delete $test(conn) ignore$test(pid).tmp
00468
00469 catch {
00470 ftp::DisplayMsg $test(conn) "Original File:\t$lsize bytes"
00471 ftp::DisplayMsg $test(conn) "Stored File:\t$rsize bytes"
00472 ftp::DisplayMsg $test(conn) "Retrieved File:\t[file size ignore$test(pid).tmp] bytes"
00473 file delete ignore$test(pid).tmp }
00474
00475 }
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485 ret test_50bfile (type loop) {
00486 global test tk_library
00487
00488 # check if enabled
00489 if {!$test(bfile)} {return}
00490
00491 ftp::DisplayMsg $test(conn) "*** TEST $loop.5 (put/get binary files) ***" header
00492 set bin_file $tk_library/demos/images/teapot.ppm
00493 set lsize [file size $bin_file]
00494 ftp::Type $test(conn) binary
00495
00496 # Put with ProgressBar
00497 # - ProgressBar init ...
00498 # - ProgressBar update ... callback defined in ftp!
00499 # - ProgressBar done
00500 ProgressBar init 0 $lsize teapot.ppm
00501 ftp::Put $test(conn) $bin_file ignore$test(pid).tmp
00502 ProgressBar done
00503
00504 # Put with ProgressBar
00505 set rsize [ftp::FileSize $test(conn) ignore$test(pid).tmp]
00506 ProgressBar init 0 $rsize ignore$test(pid).tmp
00507 ftp::Get $test(conn) ignore$test(pid).tmp
00508 ProgressBar done
00509
00510 ftp::Delete $test(conn) ignore$test(pid).tmp
00511
00512 catch {
00513 ftp::DisplayMsg $test(conn) "Original File:\t$lsize bytes"
00514 ftp::DisplayMsg $test(conn) "Stored File:\t$rsize bytes"
00515 ftp::DisplayMsg $test(conn) "Retrieved File:\t[file size ignore$test(pid).tmp] bytes"
00516 file delete ignore$test(pid).tmp
00517 }
00518
00519 }
00520
00521
00522
00523
00524
00525 ret test_60ren (type loop) {
00526 global test tk_library
00527
00528 # check if enabled
00529 if {!$test(ren)} {return}
00530
00531 ftp::DisplayMsg $test(conn) "*** TEST $loop.6 (renaming remote files) ***" header
00532 set bin_file $tk_library/demos/images/earth.gif
00533 ftp::Type $test(conn) binary
00534 ftp::Put $test(conn) $bin_file ignore$test(pid).tmp
00535 ftp::Rename $test(conn) ignore$test(pid).tmp renamed$test(pid).tmp
00536 ftp::Delete $test(conn) renamed$test(pid).tmp
00537
00538 }
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550 ret test_70append (type loop) {
00551 global test tk_library
00552
00553 # check if enabled
00554 if {!$test(append)} {return}
00555
00556 ftp::DisplayMsg $test(conn) "*** TEST $loop.7 (append ascii file) ***" header
00557 set ascii_file ftpdemo.tcl
00558 set lsize [file size $ascii_file]
00559 ftp::Type $test(conn) ascii
00560 ftp::Append $test(conn) $ascii_file ignore$test(pid).tmp
00561 ftp::Append $test(conn) $ascii_file ignore$test(pid).tmp
00562 ftp::Get $test(conn) ignore$test(pid).tmp
00563 ftp::Delete $test(conn) ignore$test(pid).tmp
00564
00565 catch {
00566 ftp::DisplayMsg $test(conn) "Original File:\t$lsize bytes ( * 2 = [expr {$lsize * 2}])"
00567 ftp::DisplayMsg $test(conn) "Appended File:\t[file size ignore$test(pid).tmp] bytes"
00568 file delete ignore$test(pid).tmp }
00569
00570 }
00571
00572
00573
00574
00575
00576
00577
00578
00579 ret test_80new (type loop) {
00580 global test tk_library
00581
00582 # check if enabled
00583 if {!$test(new)} {return}
00584
00585 ftp::DisplayMsg $test(conn) "*** TEST $loop.8 (newer) ***" header
00586 set bin_file $tk_library/demos/images/earth.gif
00587 ftp::Type $test(conn) binary
00588
00589 file copy $bin_file ignore$test(pid).tmp
00590 ftp::Put $test(conn) $bin_file ignore$test(pid).tmp
00591 set datestr "%m/%d/%Y, %H:%M"
00592
00593 set out {}
00594 catch {
00595 append out "Local File:\t[clock format [file mtime ignore$test(pid).tmp] -format $datestr -gmt 1]" \n
00596 append out "Remote File:\t[clock format [ftp::ModTime $test(conn) ignore$test(pid).tmp] -format $datestr -gmt 1]" \n
00597 }
00598
00599 ftp::Newer $test(conn) ignore$test(pid).tmp
00600
00601 catch {
00602 append out "Local File:\t[clock format [file mtime ignore$test(pid).tmp] -format $datestr -gmt 1] (after ftp::Newer)"
00603 }
00604
00605 ftp::Delete $test(conn) ignore$test(pid).tmp
00606 catch {file delete ignore$test(pid).tmp}
00607 ftp::DisplayMsg $test(conn) $out
00608
00609 }
00610
00611
00612
00613
00614
00615
00616
00617 ret test_90reget (type loop) {
00618 global test tk_library
00619
00620 # check if enabled
00621 if {!$test(reget)} {return}
00622
00623 ftp::DisplayMsg $test(conn) "*** TEST $loop.9 (reget command) ***" header
00624 set bin_file $tk_library/demos/images/earth.gif
00625 ftp::Type $test(conn) binary
00626 ftp::Put $test(conn) $bin_file ignore$test(pid).tmp
00627 set f [open ignore$test(pid).tmp w]
00628 puts -nonewline $f "123456"
00629 close $f
00630 ftp::Reget $test(conn) ignore$test(pid).tmp
00631 ftp::Delete $test(conn) ignore$test(pid).tmp
00632
00633 catch {
00634 ftp::DisplayMsg $test(conn) "Original File:\t\t[file size $bin_file]"
00635 ftp::DisplayMsg $test(conn) "Transfered File:\t[file size ignore$test(pid).tmp]"
00636 file delete ignore$test(pid).tmp
00637 }
00638 }
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648 ret test_99notfound (type loop) {
00649 global test tk_library
00650
00651 # check if enabled
00652 if {!$test(notfound)} {return}
00653
00654 ftp::DisplayMsg $test(conn) "*** TEST $loop.10 (not existing file/directory) ***" header
00655 ftp::NList $test(conn) filenotfound
00656 ftp::FileSize $test(conn) filenotfound
00657 ftp::ModTime $test(conn) filenotfound
00658 ftp::Rename $test(conn) filenotfound filenotfound
00659 ftp::Delete $test(conn) filenotfound
00660 ftp::Cd $test(conn) filenotfound
00661 ftp::RmDir $test(conn) filenotfound
00662 ftp::Put $test(conn) filenotfound
00663 ftp::Get $test(conn) filenotfound
00664 ftp::Reget $test(conn) filenotfound
00665 ftp::Newer $test(conn) filenotfound
00666 }
00667
00668
00669 ret SaveConfig () {
00670 global cnf
00671
00672 set cnf(server) [.op.f.f1.server.e get]
00673 set cnf(port) [.op.f.f1.port.e get]
00674 set cnf(username) [.op.f.f1.username.e get]
00675 set cnf(password) [.op.f.f1.password.e get]
00676 set cnf(directory) [.op.f.f1.directory.e get]
00677 set cnf(loops) [.op.f.f2.loops.e get]
00678 set cnf(debug) $ftp::DEBUG
00679 set cnf(verbose) $ftp::VERBOSE
00680
00681 set f [open $cnf(configfile) w]
00682 puts $f [array get cnf]
00683 close $f
00684 }
00685
00686
00687 ret LoadConfig () {
00688 global cnf
00689
00690 # Defaults
00691 set cnf(server) "xxx"
00692 set cnf(port) 21
00693 set cnf(username) "xxx"
00694 set cnf(password) "xxx"
00695 set cnf(directory) ""
00696 set cnf(loops) 1
00697 set cnf(debug) 0
00698 set cnf(verbose) 1
00699
00700 if {[file exists $cnf(configfile)]} {
00701 set f [open $cnf(configfile) r]
00702 array set cnf [read $f]
00703 close $f
00704 }
00705
00706 .op.f.f1.server.e delete 0 end
00707 .op.f.f1.server.e insert 0 $cnf(server)
00708 .op.f.f1.port.e delete 0 end
00709 .op.f.f1.port.e insert 0 $cnf(port)
00710 .op.f.f1.username.e delete 0 end
00711 .op.f.f1.username.e insert 0 $cnf(username)
00712 .op.f.f1.password.e delete 0 end
00713 .op.f.f1.password.e insert 0 $cnf(password)
00714 .op.f.f1.directory.e delete 0 end
00715 .op.f.f1.directory.e insert 0 $cnf(directory)
00716 .op.f.f2.loops.e delete 0 end
00717 .op.f.f2.loops.e insert 0 $cnf(loops)
00718 set ::ftp::DEBUG $cnf(debug)
00719 set ::ftp::VERBOSE $cnf(verbose)
00720 }
00721
00722
00723 ret StopTest () {
00724 global test
00725 set test(break) 1
00726 }
00727
00728
00729 ret StartTest () {
00730 global test
00731
00732 .but.f.f1.stop configure -state normal
00733 .but.f.f1.start configure -state disabled
00734
00735 .msg.f.f2.text configure -state normal
00736 .msg.f.f2.text delete 1.0 end
00737 .msg.f.f2.text configure -state disabled -fg black
00738
00739 set loops [.op.f.f2.loops.e get]
00740 set server [.op.f.f1.server.e get]
00741 set port [.op.f.f1.port.e get]
00742 set username [.op.f.f1.username.e get]
00743 set passwd [.op.f.f1.password.e get]
00744 set dir [.op.f.f1.directory.e get]
00745
00746 # open a ftp server connection
00747 set test(errors) 0
00748 set test(open) {}
00749 set test(pid) [pid]
00750 set start_time [clock seconds]
00751 ftp::DisplayMsg "" "*** Test started at [clock format [clock seconds] -format %d.%m.%Y\ %H:%M:%S ] ..." header
00752 if {[set conn [ftp::Open $server $username $passwd -port $port -progress {ProgressBar update} -mode $test(mode) -blocksize 8196 -timeout 60]] >= 0} {
00753
00754 if {$test(quote)} {
00755 ftp::DisplayMsg $conn [ftp::Quote $conn syst]
00756 ftp::DisplayMsg $conn [ftp::Quote $conn site umask 022]
00757 ftp::DisplayMsg $conn [ftp::Quote $conn help]
00758 }
00759
00760
00761 if { $dir != "" } {
00762 ftp::Cd $conn $dir
00763 }
00764
00765 # begin test loop
00766 set test(break) 0
00767 set test(conn) $conn
00768 for {set test(loop) 1} {$test(loop) <= $loops} {incr test(loop)} {
00769 if {$test(break)} {break}
00770 foreach test(proc) [lsort [info proc test*]] {
00771 if {$test(break)} {break}
00772
00773 # count entries in the after queues
00774 set test(after) [after info]
00775
00776 # run procedure
00777 eval $test(proc) $test(loop)
00778 }
00779 }
00780 if {$test(break)} {
00781 ftp::DisplayMsg "... user break!" error
00782 } else {
00783 incr test(loop) -1
00784 }
00785
00786 ftp::Close $conn
00787 set stop_time [clock seconds]
00788 set elapsed [expr {$stop_time - $start_time}]
00789 if { $elapsed == 0 } { set elapsed 1}
00790 ftp::DisplayMsg "" "************************* THE END *************************" header
00791 ftp::DisplayMsg "" "=> $loops iterations takes $elapsed seconds"
00792 ftp::DisplayMsg "" "=> $test(errors) error(s) occured"
00793 }
00794 .but.f.f1.stop configure -state disabled
00795 .but.f.f1.start configure -state normal
00796 }
00797
00798
00799 ret Help () {
00800 .msg.f.f2.text configure -state normal
00801 .msg.f.f2.text delete 1.0 end
00802 .msg.f.f2.text insert 1.0 " **** CONFIGURATION HELP *****
00803
00804 Ftp_demo is the simple user interface to the ftp test program. It
00805 checks all ftp commands of the FTP library package against an
00806 existing FTP server. It requires some configuration entries specified
00807 in the form below.
00808
00809 - Host ... Host FTP server on which the connection will be established
00810 - Username ... Users login name at host
00811 - Password ... Users password at host
00812 - Directory ... Starting directory when differs from root \"/\"
00813 - Iterations ... Count of interations for the test algorithm (default 1)
00814
00815 The message window shows all responses from the remote server, as well
00816 as report on data transfer statistics and file sizes. Two switches
00817 toggles enhanced output:
00818
00819 1. Debug...Enables debugging (return code, state, real FTP commands )
00820 2. Verbose ... Forces to show all responses from the FTP server
00821
00822 Active or passive file transfer mode is selected in the upper frame.
00823 When ftpdemo uses the active mode it waits for the server to open
00824 a connection to transfer files or get file listings. In passive mode
00825 the server waits for ftpdemo to open a connection to transfer files
00826 or get file listings. Passive mode is normally a requirement when
00827 accessing sites via a firewall.
00828
00829 Press \"Save Options\" to save these options in a configuration file.
00830 Options will be restored next time you start the ftpdemo program.
00831 Check marked test commands and start test by pressing \"Start test\"
00832 button. Any time the test program can be canceled by pressing the
00833 \"Stop test\" button.
00834
00835 NOTE:
00836 -----
00837 THE FTP_DEMO PROGRAM IS A DEVELOPMENT AND DEBUGGING TOOL RATHER THAN
00838 A USEFUL FTP USER INTERFACE. FEEL FREE TO USE IT.
00839
00840
00841 ***"
00842 .msg.f.f2.text configure -state disabled -fg darkgreen
00843 }
00844
00845
00846
00847
00848 test = (mode) active
00849
00850
00851 cnf = (configfile) "ftpdemo.cnf"
00852 LoadConfig
00853
00854 Help
00855
00856
00857
00858
00859
00860
00861
00862