Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how can get latest file from a directory?

15 views
Skip to first unread message

gde...@gmail.com

unread,
Oct 7, 2008, 6:33:29 AM10/7/08
to
how can get latest file from a directory?

spawn sftp x...@test.com
expect "Password: "
send "test\r"
expect "sftp>"
send "ls\r"
expect "sftp>"

thanks in advance!

Cameron Laird

unread,
Oct 7, 2008, 7:30:30 AM10/7/08
to
In article <c5d30f62-d306-427e...@25g2000hsk.googlegroups.com>,

The pertinent Internet-Draft exposes
atime
mtime
createtime
ctime
for SFTP. Is mtime the one you have in mind for "latest file"?

Neil Madden

unread,
Oct 8, 2008, 8:34:17 AM10/8/08
to

Something along the following lines works for me, but I'm not that
familiar with driving sftp from expect, so there may be a better way:

...
expect "sftp>"
send "ls -tr1\r"
expect "sftp>"
set file [lindex [split $expect_out(buffer) \n] end-1]
puts "last file = $file"

Cheers,

Neil

gde...@gmail.com

unread,
Oct 10, 2008, 4:51:43 AM10/10/08
to

Thanks for all the help. i want to automate download via sftp. please
suggest me better way if way's.

Donal K. Fellows

unread,
Oct 12, 2008, 8:21:46 AM10/12/08
to
gde...@gmail.com wrote:
> Thanks for all the help. i want to automate download via sftp. please
> suggest me better way if way's.

When driving sftp, expect is probably the way to go. Personally, I'd
wrap the send/expect sequences up in procedures so that I could write a
higher-level script like this:

proc getLastFile {} {


send "ls -tr1\r"
expect "sftp>"

return [lindex [split $expect_out(buffer) \n] end-1]
}

...
expect "sftp>"
set file [getLastFile]


puts "last file = $file"

Note that this is untested and might need some [global]s in there.
Season to taste. :-)

Donal.

gde...@gmail.com

unread,
Oct 12, 2008, 2:04:44 PM10/12/08
to
On Oct 12, 5:21 pm, "Donal K. Fellows"

good start for me thanks :)

0 new messages