networkguy858
networkguy858

Reputation: 159

PHPSeclib additional line breaks using write

I'm getting close to the point of simply moving this back to PERL for a specific use case of editing files via SSH. It seems no matter what I do, additional line breaks are being placed in the file. Sample variable has the following:

req_extensions = v3_req
prompt = no
[req_distinguished_name]
C = US

Using the following command, I get the output below

$ssh->write("echo '$file' > /directory/test.txt\n");

Resulting in:

req_extensions = v3_req

prompt = no

[req_distinguished_name]

C = US

Edit adding relevant debug log:

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0022, network: 0s)
00000000  00:00:00:02:00:00:00:01:65                       ........e

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0005, network: 0.0001s)
00000000  00:00:00:02:00:00:00:01:63                       ........c

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0005, network: 0s)
00000000  00:00:00:02:00:00:00:01:68                       ........h

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0003, network: 0s)
00000000  00:00:00:02:00:00:00:01:6f                       ........o

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0005, network: 0.0003s)
00000000  00:00:00:02:00:00:00:01:20                       ........ 

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0004, network: 0s)
00000000  00:00:00:02:00:00:00:01:27                       ........'

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0002, network: 0.0001s)
00000000  00:00:00:02:00:00:00:01:72                       ........r

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0001, network: 0s)
00000000  00:00:00:02:00:00:00:01:65                       ........e

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0003, network: 0.0002s)
00000000  00:00:00:02:00:00:00:01:71                       ........q

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0001, network: 0s)
00000000  00:00:00:02:00:00:00:01:5f                       ........_

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0001, network: 0s)
00000000  00:00:00:02:00:00:00:01:65                       ........e

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0007, network: 0.0006s)
00000000  00:00:00:02:00:00:00:01:78                       ........x

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0003, network: 0s)
00000000  00:00:00:02:00:00:00:01:74                       ........t

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0002, network: 0.0001s)
00000000  00:00:00:02:00:00:00:01:65                       ........e

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0003, network: 0.0002s)
00000000  00:00:00:02:00:00:00:01:6e                       ........n

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0002, network: 0s)
00000000  00:00:00:02:00:00:00:01:73                       ........s

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0001, network: 0s)
00000000  00:00:00:02:00:00:00:01:69                       ........i

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0005, network: 0.0002s)
00000000  00:00:00:02:00:00:00:01:6f                       ........o

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0005, network: 0s)
00000000  00:00:00:02:00:00:00:01:6e                       ........n

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0001, network: 0s)
00000000  00:00:00:02:00:00:00:01:73                       ........s

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0001, network: 0s)
00000000  00:00:00:02:00:00:00:01:20                       ........ 

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0004, network: 0s)
00000000  00:00:00:02:00:00:00:01:3d                       ........=

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0001, network: 0s)
00000000  00:00:00:02:00:00:00:01:20                       ........ 

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0002, network: 0s)
00000000  00:00:00:02:00:00:00:01:76                       ........v

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0001, network: 0s)
00000000  00:00:00:02:00:00:00:01:33                       ........3

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0002, network: 0s)
00000000  00:00:00:02:00:00:00:01:5f                       ........_

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0002, network: 0s)
00000000  00:00:00:02:00:00:00:01:72                       ........r

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0001, network: 0s)
00000000  00:00:00:02:00:00:00:01:65                       ........e

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0002, network: 0.0001s)
00000000  00:00:00:02:00:00:00:01:71                       ........q

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0001, network: 0s)
00000000  00:00:00:02:00:00:00:02:0d:0a                    ..........

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0001, network: 0s)
00000000  00:00:00:02:00:00:00:02:3e:20                    ........> 

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0005, network: 0.0004s)
00000000  00:00:00:02:00:00:00:02:0d:0a                    ..........

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0001, network: 0s)
00000000  00:00:00:02:00:00:00:02:3e:20                    ........> 

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0001, network: 0s)
00000000  00:00:00:02:00:00:00:01:70                       ........p

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0001, network: 0s)
00000000  00:00:00:02:00:00:00:01:72                       ........r

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0001, network: 0s)
00000000  00:00:00:02:00:00:00:01:6f                       ........o

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0001, network: 0s)
00000000  00:00:00:02:00:00:00:01:6d                       ........m

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0002, network: 0.0001s)
00000000  00:00:00:02:00:00:00:01:70                       ........p

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0002, network: 0s)
00000000  00:00:00:02:00:00:00:01:74                       ........t

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0001, network: 0s)
00000000  00:00:00:02:00:00:00:01:20                       ........ 

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0002, network: 0s)
00000000  00:00:00:02:00:00:00:01:3d                       ........=

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0001, network: 0s)
00000000  00:00:00:02:00:00:00:01:20                       ........ 

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0002, network: 0.0002s)
00000000  00:00:00:02:00:00:00:01:6e                       ........n

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0001, network: 0s)
00000000  00:00:00:02:00:00:00:01:6f                       ........o

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0002, network: 0.0002s)
00000000  00:00:00:02:00:00:00:02:0d:0a                    ..........

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0001, network: 0s)
00000000  00:00:00:02:00:00:00:02:3e:20                    ........> 

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0001, network: 0s)
00000000  00:00:00:02:00:00:00:02:0d:0a                    ..........

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0001, network: 0s)
00000000  00:00:00:02:00:00:00:02:3e:20                    ........> 

TIA

Upvotes: 1

Views: 336

Answers (2)

networkguy858
networkguy858

Reputation: 159

I'm not sure why write() was sending additional line breaks. I'm sure if I went line by line and appended to the file that would have worked. In the end, I simply used SFTP::put() which allowed me to place the @ that which wouldn't work with SSH::exec(). Thanks for all the input - it's a little different method than I would have liked, but it works.

Upvotes: 0

Shaharia Azam
Shaharia Azam

Reputation: 1986

Just pass -n and it should fix that.

$ssh->write("echo -n '$file' > /directory/test.txt\n");

-n tell not to append a new line.

Upvotes: 1

Related Questions