0

I am trying to write a shell function to scp a file to my AWS host

function ec2-scp() {
    scp -i /path/to/pem/file.pem $1 user@ec2.host.amazonaws.com:.
}

I am using it as

ec2-scp server.war

And I am getting an error:

scp: .: not a regular file

But when I replace the $1 by the file name and execute the same, it works. It's a war file that I am trying to SCP. How can i fix this?

Sandeep Kaul
  • 2,957
  • 2
  • 20
  • 36
  • 3
    If you run `set -x; ec2-scp server.war; set +x` with the function taking the argument what command do you see running? Does just removing the `.` help? – Etan Reisner May 17 '15 at 19:55
  • Thanks, I didn't know about set -+x. I see this getting execute: scp -i /path/to/pem/file.pem user@ec2.host.amazonaws.com:. server.war , now how do I get server.war in it's correct place? – Sandeep Kaul May 17 '15 at 20:29
  • That output isn't really possible given the function as written. What does `type ec2-scp` say the body of the function is? Is the body of the function perhaps `scp -i /path/to/pem/file.pem user@ec2.host.amazonaws.com:. $1` by accident? – Etan Reisner May 17 '15 at 22:51
  • That looks correct,Output: ec2-scp is a function ec2-scp () { scp -i /path/to/pem/file.pem $1 host@ip:. } – Sandeep Kaul May 18 '15 at 02:47
  • There isn't any way with the function written that way for the argument given to `ec2-scp` to be at the end of the arguments passed to `scp`. Are you sure that's the function body you get in the same shell session where `set -x` reports that the file is at the end? Do you perhaps have an old `ec2-scp` alias lying around? (I'd have expected `type ec2-scp` to report that instead of the function body though if that was the case.) – Etan Reisner May 18 '15 at 04:54
  • This is weird, but somehow it worked now. not sure what I did to get it working, I was trying out somethings to get this working. could be reload issue, not sure. Anyway, Thanks for the help. I appreciate it. – Sandeep Kaul May 18 '15 at 18:13
  • It works with the function in the post? I'm still betting on you having an incorrect function definition in the shell that was trying before. That's why I asked about whether the same shell session was having the problem as displaying that function body but . – Etan Reisner May 18 '15 at 20:12

4 Answers4

1

Try omitting the trailing dot like this:

function ec2-scp() {
    scp -i /path/to/pem/file.pem $1 user@ec2.host.amazonaws.com:
}
abligh
  • 24,573
  • 4
  • 47
  • 84
0

Is server.war a link ? because symbolic links are not regular files. Try reading this as well https://unix.stackexchange.com/questions/52634/error-using-scp-not-a-regular-file

Community
  • 1
  • 1
Inderdeep Singh
  • 105
  • 1
  • 9
0

According to user48435 answer - just add -r like: scp -i -r /path/to/pem/file.pem $1 user@ec2.host.amazonaws.com:.

Amor
  • 77
  • 2
  • 5
-1

I use scp -r -i and its working.

Yunnosch
  • 26,130
  • 9
  • 42
  • 54
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 12 '22 at 07:01
  • 1
    While this code may solve the question, [including an explanation](//meta.stackexchange.com/q/114762) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please [edit] your answer to add explanations and give an indication of what limitations and assumptions apply. – Yunnosch Sep 05 '22 at 14:26
  • 1
    Munna Biswas, please double check that my edit with the purpose of turning something which gives a "thanks" impression into a (code-only) answer, did not break the purpose of your post. If you did only want to say thanks please simply delete this post. – Yunnosch Sep 05 '22 at 14:27