Tcl-监控FTP上载百分比

Tcl-监控FTP上载百分比,ftp,tcl,Ftp,Tcl,如何在Tcl中显示::ftp::Put处理的上传百分比 例如: proc upload {host user pass dir fileList} { set handle [::ftp::Open $host $user $pass] ftpGoToDir $handle $dir # some counters for our feedback string set j 1 set k [llength $fileList]

如何在Tcl中显示
::ftp::Put
处理的上传百分比

例如:

proc upload {host user pass dir fileList} {
      set handle [::ftp::Open $host $user $pass]

     ftpGoToDir $handle $dir
      # some counters for our feedback string
      set j 1
      set k [llength $fileList]

      foreach i $fileList {
        upload:status "uploading ($j/$k) $i"
        ::ftp::Put $handle $i
        incr j
}
谢谢:)

这里有一种方法(未经测试):


它给了我这个错误:
错误#args:在执行“proc upload:executehandlefilename{chunksize 8196}”时应该是“proc name args body”
。抱歉,我是Tcl的新手:)我错过了进程主体的开始括号。固定的。我确实说过未经测试;)谢谢ftp close方法仍然存在问题,不知道发生了什么,在脚本中看不到任何ftp指针被关闭。。
proc upload {host user pass dir fileList} {
    set handle [::ftp::Open $host $user $pass]

    ftpGoToDir $handle $dir
    # some counters for our feedback string
    set j 1
    set k [llength $fileList]

    foreach i $fileList {
        upload:status "uploading ($j/$k) $i"
        upload:execute $handle $i
        incr j
    }
}

proc upload:execute {handle filename {chunksize 8196}} {
    set filesize [file size $filename]
    set sent 0
    set fid [open $filename r]

    Put_or_Append Put $handle $fid $chunksize $filename $filesize sent
    while {![eof $fid]} {
        Put_or_Append Append $handle $fid $chunksize $filename $filesize sent
    }
    close $fid
}

proc Put_or_Append {cmd handle fid chunksize filename filesize sentvar} {
    set chunk [read $fid $chunksize]
    ::ftp::$cmd $handle -data $chunk $filename
    upvar 1 $sentvar sent
    incr sent [string length $chunk]
    puts [format "sent %d bytes (%d%%)" $sent [expr {100*$sent/$filesize}]]
}