deadpickle has asked for the wisdom of the Perl Monks concerning the following question:

I am currently using Net::SFTP in order to run a perl program on Windows that connects to a linux server and uploads a file to the server. The thing is that this is being a pain when it come to public-key authorization. Also, openSSH is not maintained anyomre forcing me to use copSSH on Windows. This switch for some reason is causing me to get the error "No file name or directory". I tried to log on the the server in the terminal and discovered tha it does not like lls commands. I'm trying to fix this but this brings me to the real question. I am looking for a different way to achieve the above and was wondering how other perl programmers where achieving this. Also, I guess I will post the program code that I'm getting the error I mentioned above. I'm just going to post the transfer section of the script since its pretty long (I keep getting in trouble for my posts). I'm not sure where the problem is.
use strict; use warnings; use Tk; use Net::SFTP::Foreign; use threads; use threads::shared; use Tk::Dialog; use Tk::LabFrame; my $user:shared = 'uas'; my $server:shared = 'updraft.unl.edu'; my $wayrmt:shared = '/home/uas/Scripts/WP'; my $waylcl:shared = 'C:\Documents and Settings\deadpickle\Desktop\GRRU +VI'; ........ #SFTP Transfer sub sftp{ $|++; while(1){ if($die == 1){ goto END }; if ( $go == 1 ){ $progress = 2; if( $progress == 2){ for(;;){ if( $progress == 0){last} } } my $seconds = 120; my %args = (host=>$server, user=>$user, timeout=>$seconds) +; my $sftp = Net::SFTP::Foreign->new(%args); if ($sftp->error){ $progress =8; if( $progress == 8){ for(;;){if($progress == 0){last}} goto line; } } $progress = 1; if( $progress == 1){ for(;;){ if( $progress == 0){last} } } $gone = 1; if( $gone == 1){ for(;;){ if( $gone == 0){last} } } $sftp->put("$waylcl\\waytemp", "$wayrmt/waytemp"); if ($sftp->error){ $progress =7; if( $progress == 7){ for(;;){if($progress == 0){last}} goto line; } } $progress = 6; if( $progress == 6){ for(;;){ if( $progress == 0){last} } } $progress = 3; if( $progress == 3){ for(;;){ if( $progress == 0){last} } } line: #if($go == 0){last} if($die == 1){ goto END }; undef $sftp; #close current sftp $go = 0; #turn off self before returning $progress = 0; }else { sleep 1 } # sleep if $go == 0 } END: }

Replies are listed 'Best First'.
Re: Connecting to a Server
by shmem (Chancellor) on Jun 23, 2007 at 12:04 UTC
    $progress = 2; if( $progress == 2){ for(;;){ if( $progress == 0){last} } }

    What do you expect this code snippet to do? I expect it to sit in the for (;;) loop forever, since there's nothing in the loop that would set $progress=0 - or is this a variable shared between threads? Anyways, such a tight loop which tests just one variable is a wonderful way to hog your machine's CPU.

    Why are you testing $progress just after setting it? ....ah, now. This is some variable you can control from TK, right?

    Searching... ah, this essentally is code you got from zentara as an answer to a previous post from you, with formatting gone wild.

    Stripping all those $progress blocks (you could have done that before posting), what remains is this:

    sub sftp{ $|++; 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); if ($sftp->error){ goto line; } $sftp->put("$waylcl\\waytemp", "$wayrmt/waytemp"); if ($sftp->error){ goto line; } line: 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: }

    The second goto line; - apart from goto being bad practice - doesn't make any sense; shouldn't that be goto END ? Removing all that goto stuff, your code becomes

    sub sftp{ $|++; while(1){ last if $die == 1; if ( $go == 1 ){ my $seconds = 120; my %args = (host=>$server, user=>$user, timeout=>$seconds) +; my $sftp = Net::SFTP::Foreign->new(%args); last if ($sftp->error); $sftp->put("$waylcl\\waytemp", "$wayrmt/waytemp"); last if ($sftp->error); last if $die == 1; undef $sftp; #close current sftp $go = 0; #turn off self before returning } else { sleep 1; } # sleep if $go == 0 } }

    Now, the only relevant line I see is

    $sftp->put("$waylcl\\waytemp", "$wayrmt/waytemp");

    Does the directory $wayrmt exist on the remote server?

    (I keep getting in trouble for my posts)

    That's because you really make it difficult to help you.
    Fix your code formatting, throw out stuff that isn't relevant. See How (Not) To Ask A Question.

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re: Connecting to a Server
by quester (Vicar) on Jun 23, 2007 at 22:09 UTC
    You mentioned that "openSSH is not maintained anymore". I don't agree. According to the OpenSSH home page the last release was OpenSSH 4.6/4.6p1 on March 9, 2007.

    If you meant specifically OpenSSH for Windows, OpenSSH_4.6p1 has already been released for Cygwin. (By the way, IMHO, getting any real work done on Windows without Cygwin is an exercise in futility.)

    If you are referring specifically to Network Simplicity OpenSSH for Windows, the author's stated reason that he doesn't maintain it any more is that "I no longer have the time to maintain a package that is, for the most part, unnecessary due to improvements in the installation process of Cygwin." I agree, the Cygwin installation process has become fairly painless.

    I would assume that SSHwindows has not been released for a few years now for the same reason, that Cygwin is now a good alternative.

Re: Connecting to a Server
by deadpickle (Pilgrim) on Jun 25, 2007 at 19:42 UTC
    I figured out the problem. But this is not what I wanted to talk about. What I want to do is get away from using openSSH or Cygwin. I want this program to connect to a web server ( http://updraft.unl.edu/~uas/ ) and download the files on that server then disconnect. I want to get away from cygwin and/or openSSH to simplify this process and require less supporting software. I wanted to know what are the ways I can achieve this goal? (ex. Sockets, Magic, ...) Also, I would like to do this on both a linux and Windows box.

      Perhaps you should consider Putty, which has a command-line SSH client for Windows, along with other related tools.

      ----Asim, known to some as Woodrow.