Yah thanks alot. I got a little of that before you sent it, but definitly not all of it. The program works great, does everything I want it to do. Now all that needs to be done is to make a listbox that prints all the print statements to it. It got some of it to work but when $msg=2 and the program enters the sub lstmsg, when it gets to the listbox insert the program stops. If I take the insert out it runs just fine. How can I fix this?
This is a snippet of just the subroutines with the omitted Tk widgets.
sub sub1 { if($btn->cget(-text) eq 'Connect'){ $go = 1; $btn->configure(-text=> 'Stop'); $msg = 1; lstmsg(1); } else{ $go = 0; $btn->configure(-text=> 'Connect'); } } sub lstmsg{ if($msg == 1){ $lstbx->insert('end',"Connecting... Asking for Password..."); #$lstbx->insert('end', "sftp connected $user $server"); } if($msg == 2){ print "huh\n"; $lstbx->insert('end', "sftp connected $user $server"); goto AFTER; } } sub sftp{ $|++; #now go into a waiting loop, where you wait for $go to be 1. when +$go = 1, the sftp will keep sending the file. #the only way to break out is to set $die=1 while(1){ if($die == 1){ goto END }; if ( $go == 1 ){ my $seconds = 120; my %args = (host=>$server, user=>$user, timeout=>$seconds) +; my $sftp = Net::SFTP::Foreign->new(%args); print "What\n"; $msg = 2; if($msg == 2){lstmsg(1)}; AFTER: print "happy\n"; for(;;){ $sftp->put("$local", "$remote"); print "fake file being sent\n"; sleep 2; if($go == 0){last}; if($die == 1){ goto END }; } undef $sftp; #close current sftp $go = 0; #turn off self before returning } else { sleep 1 } # sleep if $go == 0 } END: print "sftp stopped thread ending\n"; } sub clean_exit{ my @running_threads = threads->list; if (scalar(@running_threads) < 1){print "\nFinished\n";exit} else{ $die = 1; $thr->join; exit; } }

In reply to Inserting Text into Listbox from a Thread by deadpickle
in thread Looping File transfer using SFTP in TK by deadpickle

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.