I've never used Expect::Simple, but here it is in plain Expect:

#!/usr/bin/perl use strict; use warnings; use Expect; my $REMOTE = 'name@server:/dir'; my $LOCAL = 'file'; my $cmd = "sftp $REMOTE"; my $exp = Expect->spawn($cmd) or die; $exp->expect(120, "password: ") or die; $exp->send("dummy\r"); $exp->expect(120, "sftp> ") or die; $exp->send("put $LOCAL\r"); $exp->expect(600, "sftp> ") or die; $exp->send("bye\r"); $exp->close();

It behooves you to add reasonable messages to the die commands, since all Expect scripts inevitably break.

The code may need tweaking depending on software versions. For the record, here's what I used:

$ perl -v This is perl, v5.6.1 built for i386-linux $ perl -MExpect -le 'print $Expect::VERSION' 1.15 $ strings `which sftp` | grep sftp-client @(#)$OpenBSD: sftp-client.c,v 1.33 2002/06/23 09:30:14 deraadt Exp $

In reply to Re: SFTP and the Pointy-Haired manager by TilRMan
in thread SFTP and the Pointy-Haired manager by FatDog

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.