LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   scp command "failed to read binary packet data!" (https://www.linuxquestions.org/questions/linux-newbie-8/scp-command-failed-to-read-binary-packet-data-4175492163/)

noochi01 01-22-2014 10:40 AM

scp command "failed to read binary packet data!"
 
Hi Guys,

I'm new to linux so please bear with me...

I'm using scp to copy a file from my ftp server to an ftp server outside my organization. My cert is trusted by the other server, so autehtication is not an issue. I know this becuase I can sftp to the server without any issue. Below is my example:

scp /home/localuser/localdir/Test.txt
-oPort=RemotePort username@RemoteIP:Test.txt

When I run the above command, even with -v. -vv. or -vvv, it gets to

"Sending command: scp -v -d -t Test.txt"
"Received disconnect from RemoteIP:2:Failed to read binary packet data!"
"lost connection"

If I run sftp -oPort=RemotePort username@IP

It connects every time.....

Any thoughts?

Thanks,
Mike

pingu 01-22-2014 11:58 AM

You specify port in wrong place. The command should be
scp -oPort=RemotePort /home/localuser/localdir/Test.txt username@RemoteIP:Test.txt

noochi01 01-22-2014 01:43 PM

Hi Pingu,


Thanks for the info, but when I tried the command as you said, I still receive...
Received disconnect from RemoteIP:2:Failed to read binary packet data!
lost connection

pingu 01-22-2014 02:08 PM

Looking closer now, I missed one thing:
"username@RemoteIP:Test.txt" - that's not correct! It should be "username@RemoteIP://Test.txt".
But then, you must have write permission in remote directory, so it's rather
Code:

scp -oPort=RemotePort /home/localuser/localdir/Test.txt username@RemoteIP://home/<username>/
(you don't need to specify remote filename unless you want to rename the file.)

Another thing that can prevent scp from working is if there is a script running at every login. If so, scp will try to execute that script, fails, therefore stops and returns an error.

jpollard 01-22-2014 05:51 PM

It isn't that the script causes a problem. Running a script is not a problem.

What causes problems is if that script generates output to the terminal...

scp runs ssh, with no pseudoterminal attached. This allows any such script to check before generating output... Any output in this situation BEFORE the file transfer occurs will cause an error as the data protocol is violated. I believe the first character sent as part of the protocol is a null byte. This null byte signals that the scp (server process) is ready for data exchange (direction is arbitrary). The client is waiting for that null byte - if something else comes in instead - you get the error.

This situation occurs frequently with bashrc files that setup a terminal (things like setting status, output of a fortune string...).

If this is the issue, comment out the commands starting it for testing. If the scp works, then put some kind of terminal test (one is to test for a prompt string - if no pseudoterminal is attached, the prompt string is empty/undefined).

noochi01 01-31-2014 12:21 PM

Update.... I tried everything possible, but was unable to get scp to fuction properly. As soon as I changed it to sftp, I was able to connect successfully. I wish I had an answer for you.

Thanks!

pingu 01-31-2014 12:39 PM

Could you post your /etc/ssh/sshd_config please.


All times are GMT -5. The time now is 11:58 AM.