Expect and ftp



  • 1. Creating windows without controls (Delete, Minimize, Restore, Control button)
    I am looking for a way to create tk windows without controls like Delete, Minimize, Restore, Control button. The top should have just the TITLE. If it is not possible to creat such a window, how can I diable the actions. Nothing to be done when someone clicks on these buttons. Thanks for your help. -anand
  • 2. Dynamic Procedure Definition
    Can someone help me with the syntax to dynamically load a procedure ? e.g. set myproc "proc Sum \{num1 num2} \{ return \[expr \$num1 + \ $num2]; }"; how can I define Sum using $myproc ?

Expect and ftp

Postby Vincent Yau » Sun, 04 Apr 2004 03:13:11 GMT

Dear All:

Not sure if this is the place to ask Expect question.
Hope this question is appropriate.

I am using Expect to download stuff from an ftp site.
I am trying to use mget *.* so I can grab
everything out of a directory.
I used get <filename> from within Expect and it
works great.

However, Expect just hangs when I 

   send "mget *.*\r"

No transfer at all.  I verified that the ftp server
is ok as I am doing a manual "mget *.*" in another shell
for a different data directory.

Any idea?


Re: Expect and ftp

Postby Bruce Hartweg » Sun, 04 Apr 2004 03:35:04 GMT

not sure why it would hang, but I will mention the expect
isnlt needed for ftp, you can do it in plain tcl using the
ftp package - read  http://www.**--****.com/ 


Re: Expect and ftp

Postby claird » Sun, 04 Apr 2004 04:03:55 GMT

In article <tnibc.3$ XXXX@XXXXX.COM >,

Me, too.  Unless you have a specific reason for using ftp with
Expect as you describe, I strongly urge you to rely on tcllib's
ftp package.

If you *do* have a good reason for using Expect, though, I'm
confident we can help you make it work.

Cameron Laird < XXXX@XXXXX.COM >
Business:   http://www.**--****.com/ 

Re: Expect and ftp

Postby claird » Sun, 04 Apr 2004 21:59:48 GMT

In article < XXXX@XXXXX.COM >, I applauded
Mr. Yau (by e-mail) is among those who wonders if the ftp
package "has mget support".


That's simple enough.  However, it's only a step or two more
to use what ftp *does* have:

      # This model doesn't handle exceptions at all, and so on.
    foreach file_name [ftp::NList $connection $directory_pattern] {
      ftp::Get $connection $file_name

Cameron Laird < XXXX@XXXXX.COM >
Business:   http://www.**--****.com/ 

Similar Threads:

1.expect:ftp:downloading new files from a huge ftp account

Hi all,
I have a remote ftp account to a directory with 40 GO of files in a
tree of directories.
I have a list of 175000 path/filenames coming from that ftp account
(same arborescence).
I would like to write an expect script that connect to the ftp account,
browse the three and get all files that are not in my list.
does anybody ever write such a script or knows where to find infos that
could help me.
many thanks

2.Expect script to manage FTP

I'm running HP-UX 11i with Expect installed. I'd prefer not to install
any other software.

I need to visit multiple FTP sites, send and receive files from each
site, and delete successfully downloaded files from the source FTP
sites, and archive successfully uploaded files on my site.

I have some experience using Expect to automate FTP, but it's been
limited to simple put and get transactions, with no need to delete or
archive files. Typically I write an expect script for each FTP site I
want to visit, and manage everything but the FTP in a shell script. I'm
comfortable with that model, but also open to other suggestions.

Thanks for taking the time to read this, and for any suggestions.

Here's what I have so far:
#! /usr/local/bin/expect

spawn ftp -i ftp.somesite.com
expect "root): "
send "FTPUSER\r"
expect "assword:"
send "mypassword\r"
expect "ftp> "
send "cd Outgoing/Prod\r"
expect "ftp> "
send "lcd /var/EDI/somesite/IN\r"
expect "ftp> "
send "binary\r"
expect "ftp> "
send "mget *.pgp\r"
expect -timeout 999 "ftp> "
send "lcd /var/EDI/somesite/OUT\r"
expect "ftp> "
send "cd ../../Incoming/Prod\r"
expect "ftp> "
send "mput *.pgp\r"
expect -timeout 999 "ftp> "
expect "ftp> "
send "bye\r"

3.FTP using expect

I am new to Expect.( This is a very basic expect program, please let me
know if there is a
separate group where I can post this query)
I am simply trying to ftp my local mail server , entering username and
password read from a file and then exitting.
Sometimes this program runs fine till the end and exits properly, but
sometimes it hangs in between. Like sometimes after entering user name
, or sometimes after entering passowrd or sometimes during ftp to the
Following is the program, please let me know if there is something
wrong with the program.
I tried it on various server and even tried telnet program but face the
same problem.

package require Expect

spawn ftp indmail
set timeout -1
set file [open "C:/Tcl/bin/password.txt" "r"]
gets $file username
gets $file password
expect "User*"
send "$username\r"
expect "Password:"
send "$password\r"

expect "ftp>"
send "binary\r"
expect "ftp> "
send "bye\r"

4.Expect: sending larger files with ftp-inband

5.[Expect] Get, then move files within FTP site

M Bourgon wrote:
> Trying to do the following, and it looks like Expect is probably my
> best bet. Any help greatly appreciated
> 1) Log onto ftp site
> 2) Go to folder
> 3) GET all files matching basename*.txt
> 4) MOVE those files to a subfolder on the ftp site. I don't need to
> move it on MY computer, I want to move the files on the site to a
> subfolder, so that if there are any problems the files are still
> accessable. This is acceptable by the site owner.
> I'm not sure how to get it to evaluate from the responses - ideally
> I'd do a LIST, stick that in some sort of array, then loop through and
> do a GET then RENAME.
> Example:
> spawn ftp myftp
> expect "username:"
> send "hi\r"
> expect "password:"
> send "mom\r"
> expect "ftp>"
> send "prompt\r"
> expect "ftp>"
> send "cd getme\r"
> expect "ftp>"
> send "mget basename*.txt\r"
> expect "ftp>"
> (code I need - move all files I just got to folder getme\processed)
> send "bye\r"
> expect eof

     I hate it when people do this. My excuse is that you don't sound as
     though your are certain that expect is your best bet for this task.

Have you looked at the ftp package in tcllib? It looks to me as though:

set chn [ftp::Open site username password]
ftp::Cd $chn wherever
foreach file $files [ftp::List $chn basename*.txt] {
     ftp::Rename $chn $file somewhereElse
ftp::Close $chn

should come pretty close to what you're after.


6. [Expect] Get, then move files within FTP site?"

7. Permission to FTP to ftp.taygeta.com/

8. Active State base-tcl8 vfs::ftp Error can't find package ftp

Return to tcl


Who is online

Users browsing this forum: No registered users and 43 guest