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

Is it possible to "upload and run script" through CLI command

I can upload script through System > Advanced and then it is automatically executed in forti OS 5.6.2

how can i perform the same (upload and run script) through CLI command.

Esteemed Contributor III




Look at this   thread on a just  few of many ways you can run scripts at the cmd






PCNSE NSE StrongSwan
New Contributor

Thanks for your reply, emnoc.


Actually, I am looking for a CLI command to upload Script file on Fortigate 30 E  and execute it.


I can achieve this in GUI mode (System > Advanced > "upload and run script"). But I didn’t find any option to perform the same action in CLI…




Interesting too. Have anyone an example? I've uploaded my scripts, but no place, no cmd that i can execute this. 

Fortigate 60E v7.x (GA)

Fortigate 60E v7.x (GA)

And here the solution:

Fortigate 60E v7.x (GA)

Fortigate 60E v7.x (GA)
New Contributor

There are a number of libraries that allow you to mimic commands that you would enter through SSH.

Attached is a python program that uses Paramiko (a library that lets you SSH to a host and execute commands). There are other libraries like "Expect" but "Paramiko" has come into favour with programmers and automators.

We use it extensively to automate tasks from a centralized location (e.g. crontabs, Jenkins etc).

Works well with Python 2.7 but can be upgraded to Python 3.x. Note: You will need to pip install the paramiko libraries for this to work.


The script does the following but you can have it do whatever you want. You could even use this script to upload a script to "config system auto-script" by sending the appropriate commands:


% ssh admin@
fortigate # config vdom
fortigate (vdom) # edit DMZ
fortigate (DMZ) # config user local
fortigate (local) # edit bill
new entry 'bill' added
fortigate (bill) # set type radius
fortigate (bill) # set radius-server MFA
fortigate (bill) # next
fortigate (local) # edit ted
new entry 'ted' added
fortigate (ted) # set type radius
fortigate (ted) # set radius-server MFA
fortigate (ted) # next
fortigate (local) # end
fortigate # exit




# - Connect to a Fortigate using paramiko/SSH, connects into a specific VDOM, add two users from a list and exit

import paramiko
import time

sleepyTime = 0.5
receiveTime = 20000
fortigateHostname = ''
fortigateUserName = 'admin'
fortigatePassword = 'XXXXXXXXXXXXX'

verbose = True

def doCommand(remote_conn,command):
    remote_conn.send(command + "\n")
    output = remote_conn.recv(receiveTime)
    if verbose:

def connectToVDOM(remote_conn):
        remote_conn = remote_conn.invoke_shell()
        doCommand(remote_conn,"config vdom")
        doCommand(remote_conn,"edit DMZ")
    except KeyError as e:

def usersToAdd(userList, remote_conn):
        doCommand(remote_conn,"config user local")
        for user in userList:
            doCommand(remote_conn,"edit "+user)
            doCommand(remote_conn,"set type radius")
            doCommand(remote_conn,"set radius-server MFA")
    except KeyError as e:

def disconnectFromFG(remote_conn):
    except KeyError as e:

# Connect to the Fortigate using using the paramiko and SSH
    remote_init_conn = paramiko.SSHClient()
    remote_init_conn.connect(fortigateHostname, username=fortigateUserName, password=fortigatePassword, look_for_keys=False, allow_agent=False)
except (paramiko.ssh_exception.AuthenticationException, paramiko.ssh_exception.SSHException) as ex:
    print("[-] %s:%s - %s" % (fghost, fgport, ex))
except paramiko.ssh_exception.NoValidConnectionsError:
    print("[-] %s:%s - %s" % (fghost, fgport, ex))

# User list to add
users = ["bill", "ted"]
# Connect to the VDOM
remote_conn = connectToVDOM(remote_init_conn)
# Add some local users
usersToAdd(users, remote_conn)
# Logout

Top Kudoed Authors