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

  • Home
  • SEARCH
  • 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 6358319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:21:03+00:00 2026-05-24T23:21:03+00:00

Here i am making a connection b/w two machines using telnet and in the

  • 0

Here i am making a connection b/w two machines using telnet and in the remote host i am creating a file named “file.txt” and storing the result of the “ls” command execution in the file.txt. now i need to send the file to the local host. i dont know how to do it. anybody who knows it kindly help me out here.

#!/usr/local/bin/expect 
spawn telnet <machine ip> 
expect "login:" 
send "<username>\n" 
expect "Password:" 
send "<password>\n" 
expect "bash"
send " ls > file.txt\r "
expect "bash"
send " cat file.txt \r "
expect "bash"
send " command for copying file to the localhost computer\r"
expect "bash"
send "exit\r"
  • 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-24T23:21:04+00:00Added an answer on May 24, 2026 at 11:21 pm

    You’re strongly recommended to use ssh and scp for this task.

    #!/usr/local/bin/expect
    
    ### Factor these out
    set user <username>
    set pass <password>
    set host <machineIP>
    
    ### Get the file list into a file remotely
    spawn ssh $user@$host sh -c {ls -1 >file.txt}
    expect {
        "Password:" {
            send "$pass\r"
            exp_continue
        }
        eof {
            close
        }
    }
    ### Copy the file to the local machine
    spawn scp $user@${host}:file.txt .
    expect {
        "Password:" {
            send "$pass\r"
            exp_continue
        }
        eof {
            close
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the situation: I am making a small prog to parse server log
Here is my problem. I have created a pretty heavy readonly class making many
Im making an asynchronous call from a class to another. Here is my actual
Okay so here's what I'm doing. I'm making a request to a server to
I need help making AOP work. What am I missing here? <?xml version=1.0 encoding=UTF-8?>
Alright, here goes. I'm making a very basic app, and I want the user
Okay, I think I'm just making a stupid mistake here, but I want to
I am using Redis to store two databases : 0 and 1 via the
I'm making a rails 3.1 app using carrierwave to upload files to aws s3.
I'm using Visual Studio 2008 Pro. I'm probably missing something very obvious here, but

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.