Author: brad Date: 2006-06-24 23:51:08 +0000 (Sat, 24 Jun 2006) New Revision: 16508
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=16508 Log: Added copy_file function, to copy a text file from the local unix host to the remote windows host. Modified: branches/SOC/bnh/expect/common.exp Changeset: Modified: branches/SOC/bnh/expect/common.exp =================================================================== --- branches/SOC/bnh/expect/common.exp 2006-06-24 23:34:44 UTC (rev 16507) +++ branches/SOC/bnh/expect/common.exp 2006-06-24 23:51:08 UTC (rev 16508) @@ -2,6 +2,69 @@ # Copyright Brad Henry <[EMAIL PROTECTED]> 2006 # Released under the GNU GPL v2 or later. +# This function copies a text file over telnet from the local unix host +# to the remote windows host. +proc copy_file { remote_prompt in_filename out_filename } { + set default_err_str "Unknown error in function copy_file" + set err_str $default_err_str + + # The octal ASCII code for Control-Z is 032. + set CTRLZ \032 + + # Open local file and read contents. + set in_file [open $in_filename r] + set in_data [read $in_file] + + # Initiate copy on remote host. + set cmd "copy con $out_filename\r" + send $cmd + + # Separate $in_data into lines and send to remote host. + set out_data [split $in_data "\n"] + foreach out_line $out_data { + send $out_line + # We might as well do a unix -> windows line conversion. + send "\r\n" + # Are we overwriting an existing file? + # If so, exit so we can handle it. + expect { + "(Yes/No/All)" { + send "NO\r" + expect_prompt $remote_prompt + set err_str "File exists" + } \ + $out_line { + set err_str "OK" + } \ + timeout { + set err_str "Function copy_file timed out while copying $in_filename" + } + } + if { $err_str != "OK" } { + return $err_str + } else { + set err_str $default_err_str + } + } + + # ^Z\r to complete the transfer. + send $CTRLZ + send "\r" + expect { + "file(s) copied." { + set err_str [expect_prompt $remote_prompt] + } \ + $remote_prompt { + set err_str $default_err_str + } \ + timeout { + expect_prompt $remote_prompt + set err_str "Function copy_file timed out while finishing copy of $in_filename" + } + } + return $err_str +} + # This function waits for the command prompt and reports an error on # timeout. proc expect_prompt { remote_prompt } {
