in reply to Re: Looping File transfer using SFTP in TK
in thread Looping File transfer using SFTP in TK

Thanks for the responses, they are very helpful. What I want is for the sftp to disconnect when the Stop button is pushed. that way the script allows the user to change the variables and run the transfer again. Right now I am trying to understand how zentara's code works since it incorporates syntax I have never seen (and it seems to make it easier). One problem is that the program connects right away not allowing the user to change the variables before it is connected to the server. I moved the SFTP connection to work only when $go = 1, that way it only connects of you push connect. But you cant change the variables like username from jlahowet to something else. It wont pass the new value to the thread for some reason, any help?
  • Comment on Re^2: Looping File transfer using SFTP in TK

Replies are listed 'Best First'.
Re^3: Looping File transfer using SFTP in TK
by zentara (Cardinal) on Apr 11, 2007 at 11:59 UTC
    Well to save you the head-scratching( I'm familiar with it due to hours of my own head-scratching :-) ), here is how to do it so each sftp run can be different.

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
      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?
        You are making a big mistake in trying to access one thread from another. Remember the rules I stated for threaded-Tk apps. No Tk code in the thread. Don't try to access Tk widgets from the thread. And in your case, don't use a goto, to try to jump into a thread.

        Without doing the code for you, this is how you would do it.

        1. Make $msg, and $msg_return shared variables.

        2. Like I did with the file counter, setup a timer in the main thread to watch for the value of $msg. At the point where you test for $msg==2 in the thread, go into a wait-loop in the thread,waiting for the shared-value $msg_return == 1. When that happens, continue in the thread.

        3. When the main thread detects, $msg==2, it can do whatever is needed, then set $msg_return=1 and $msg=0, so the thread can continue.

        Remember, ALL Tk stuff has to be done in the main thread. All communication with the worker thread(s) has to be done through simple shared-variables.


        I'm not really a human, but I play one on earth. Cogito ergo sum a bum
Re^3: Looping File transfer using SFTP in TK
by zentara (Cardinal) on Apr 11, 2007 at 11:24 UTC
    Yeah, to make a new connection each run, move the connect to inside the go loop. To use new connection info for each connection, make them shared varaibles. Like:
    my $user:shared = 'jlahowet'; + my $server:shared = 'mistral.unl.edu'; + my $lcl:shared = '/home/deadpickle/Desktop/Virtual Cockpit/uavposition +'; my $rmt:shared = '/home/jlahowet/UAV/COORDS/uavposition'; #my $thr = threads->new(\&sftp, @setup); my $thr = threads->new(\&sftp); #then in your thread-code use the shared vars instead of #using the passed in @setup array
    You already have your entry widgets to setup to automatically change the vars with -textvariable. There is one thing to watch out for: sometimes the threads will not automatically pick up changes in textvariables, you might have to manually read them, but try it first, you may get lucky.

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum