Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6070119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:53:50+00:00 2026-05-23T09:53:50+00:00

I am uploading a file via ftp using expect . The file is piped

  • 0

I am uploading a file via ftp using expect. The file is piped into my bash script.

#!/bin/bash
HOST='example.com'
USER='XXX'
PASSWD='XXX'

expect << EOT
spawn ftp $HOST
expect "Name*:"
send "$USER\r"
expect "Password:"
send "$PASSWD\r"
expect "ftp>"
send "binary\r"
expect "ftp>"
send "prompt\r"
expect "ftp>"
send "put - $1\r"  ####
expect "ftp>"
send "bye\r"
expect eof
EOT

On the highlighted line I want ftp to get access to the main script stdin.

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:53:51+00:00Added an answer on May 23, 2026 at 9:53 am

    I believe the key to what you are looking for is Expect’s interact command. You’d get a script like this:

    #!/usr/bin/env expect
    
    # Set these in the Tcl way, not the bash way
    set HOST "example.com"
    set USER "XXX"
    set PASSWD "YYY"
    
    # You should recognize this bit...
    spawn ftp $HOST
    expect "Name*:"
    send "$USER\r"
    expect "Password:"
    send "$PASSWD\r"
    expect "ftp>"
    send "binary\r"
    expect "ftp>"
    send "prompt\r"
    expect "ftp>"
    
    # New stuff starts here
    send "put - [lindex $argv 0]\r"
    interact {
        "ftp>" { return }
    }
    send "bye\r"
    wait
    exit
    

    I’ve rewritten your script so it doesn’t use a here document, because that would have interfered with the reading of the content (here-docs are presented as stdin…) and switched it to use a few more idiomatic ways of doing things (idiomatic argument access being the main one).

    That said, if I was doing this sort of thing for real, I’d look into using the ftp package from Tcllib as that talks the protocol directly instead of using a possibly-problematic subprocess. (Indeed, if you were going to be doing this on Windows, you’d have to do it that way because of quirks of how Expect and http://FTP.EXE work on that platform).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my project I have a file uploading feature. Files are uploaded via FTP.
I'm uploading a fairly large file with urllib2 to a server-side script via POST.
I am trying to upload a file via ftp using FtpWebRequest as below: ftpRequest
When uploading a file (jpeg) via a form in IE7 I am seeing a
I have found numerous examples on uploading a file to a web server via
While user uploading a file, is it possible to know if the uploaded file
I working on adding file uploading to my web application. I'm using an iframe
I am currently looking in to some file uploading using Java Server Faces. I've
I have been using Indy to transfers files via FTP for years now but
We have a few 100 users logging in via FTP and uploading files. Our

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.