Support Forum
The Forums are a place to find answers on a range of Fortinet products from peers and product experts.
TC_Hessen
New Contributor

Reading config of fgt with scp/php

Hi, I tried to fetch a config-file of our Fortigates using the php command ssh2_scp_recv, but it does not work. The connection is established using the ssh2-class and works without and problem. Both, password and key-authentication works, opening a virtual shell also works. But a simple csp failes with PHP Warning: ssh2_scp_recv(): Unable to receive remote file in[...] Using scp on the linux shell is ok, but I do not like a use a shell-excecute in such a script. Any hints? I am using php 5.4.4, libssh2 1.4.2 on debian wheezy/stable.
best regards, TC
best regards, TC
10 REPLIES 10
emnoc
Esteemed Contributor III

Suggestions: Have you debug the enc-cipher that' s used with the php tool & for scp specifically ? Have you tried all common ciphers to see what you FGT likes and accepts ? Have you tried the SCP-php tool against a non-fortigate device like a linux-server to ensure it' s not a problem with the utility ?

PCNSE 

NSE 

StrongSwan  

PCNSE NSE StrongSwan
TC_Hessen
New Contributor

Sure. Copying between other linux-servers work without problem.
 $connection = ssh2_connect(' 10.10.1.253' , 22); // <- no error
 ssh2_auth_password($connection, ' admin' , ' <foobar>' ); // <- no error
 ssh2_scp_recv($connection, ' sys_config' , ' sys_config' ); // <- PHP Warning:  ssh2_scp_recv(): Unable to receive remote file in [...]
 
That' s a very simple example that works with our linux-servers, but not with the fgt. It is also possible to open a stream (interactive session) on this connection to send and receive commands, but not a simple scp.
best regards, TC
best regards, TC
emnoc
Esteemed Contributor III

$connection = ssh2_connect(' 10.10.1.253' , 22); // <- no error ssh2_auth_password($connection, ' admin' , ' <foobar>' ); // <- no error ssh2_scp_recv($connection, ' sys_config' , ' sys_config' ); // <- PHP Warning: ssh2_scp_recv(): Unable to receive remote file in [...]
Sow when you are on the host trying to grab the file & execute the following; scp admin@10.10.1.253:sys_config ./ that works 100% of the time? Maybe you need to escape the " -" in the file name ?

PCNSE 

NSE 

StrongSwan  

PCNSE NSE StrongSwan
TC_Hessen
New Contributor

Yes, that works 100% whether with password authentication or public key. I cannot see the different and I have no idea how to get a more verbose logfile on the fortigate where I could see the parameters of the copy command. I use " diag deb appl sshd -1"
best regards, TC
best regards, TC
Dave_Hall
Honored Contributor

The CLI ref manual shows a " execute cli check-template-status" command. Just curious to know what that command shows.

NSE4/FMG-VM64/FortiAnalyzer-VM/6.0 (FWF30E/FW92D/FGT200D/FGT101E/FGT81E)/ FAP220B/221C

NSE4/FMG-VM64/FortiAnalyzer-VM/6.0 (FWF30E/FW92D/FGT200D/FGT101E/FGT81E)/ FAP220B/221C
TC_Hessen
New Contributor

 login as: admin
 Authenticating with public key " tc" 
 FG-GW # execute cli check-template-status
 the scp script template is stopped.
 
Whether I run the scp script or not.
best regards, TC
best regards, TC
ede_pfau
SuperUser
SuperUser

You could try
diag deb ena
 diag deb cli 7
to see a bit more on the command line. I' ve tried doing this for a while now without success. Using Secure Shell ssh v3.2.9 and pscp from the putty installation. Command just freezes. Login via ssh shell is no problem, using the imported public key.
Ede Kernel panic: Aiee, killing interrupt handler!
Ede Kernel panic: Aiee, killing interrupt handler!
Dave_Hall
Honored Contributor

@TC_Hessen What do you have set for stream_set_blocking?

NSE4/FMG-VM64/FortiAnalyzer-VM/6.0 (FWF30E/FW92D/FGT200D/FGT101E/FGT81E)/ FAP220B/221C

NSE4/FMG-VM64/FortiAnalyzer-VM/6.0 (FWF30E/FW92D/FGT200D/FGT101E/FGT81E)/ FAP220B/221C
TC_Hessen
New Contributor

Nothing. stream_set_blocking is used for streams, but ssh2_scp_recv does not use streams. Compare my code segment above or the online-help
best regards, TC
best regards, TC
Announcements

Select Forum Responses to become Knowledge Articles!

Select the “Nominate to Knowledge Base” button to recommend a forum post to become a knowledge article.

Labels
Top Kudoed Authors