Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have read through several threads (which have been helpful) and I'm still getting an error when trying to sftp a file (client wants it to be sftp'ed)

Here is the script:



spawn sftp -o Port=$PORT $USER@$HOST
expect "sftp>"
spawn put $FILE

The error I am receiving is:

spawn sftp -oPort=XXXX root@XX.XX.XX.XX
Connecting to XX.XX.XX.XX...
sftp> spawn put /tmp/RANDY
couldn't execute "put": no such file or directory
    while executing
"spawn put /tmp/RANDY"

The file exists and is in the correct directory.

share|improve this question

The second spawn in your Expect script should be send, you should quote what you're sending to the spawned process, and you've left off the CR (Carriage Return, a.k.a. Enter):

send "put $FILE\r"

Also, you probably don't want the interact command. This probably makes more sense in its place:

expect "sftp>"
send "exit\r"
share|improve this answer

where is password or authentication happening , For sure you have to authenticate first and then you should not get that error.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.