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.


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"

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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