1

I'm running this python script wherein the output of the python script will be display in web browser so I'm using PHP for this. I'm using netmiko in python for upgrading the router. The main problem is when I run the python script in CMD it perfectly works but when I run it in Web browser using some html and php not all the script is not running. It gives me the below error:

scp.SCPException: scp: c7200-ipbasek9-mz.150-1.M10.bin: No such file or directory 

This is the code in python with netmiko

from netmiko import ConnectHandler, cisco
from netmiko import FileTransfer
from netmiko import SCPConn
from datetime import datetime
import sys

ip_addr = Type[0]
device_type = Type[1]
password = Type[2]
source_file = Type[3]
print ("IP:" + ip_addr + '\n'
"Model:" + device_type +'\n'
"IOS:" + source_file + '\n')
start_time = datetime.now()

s_file = source_file
d_file = source_file
net_device = {
    'device_type': 'cisco_ios',
    'ip': ip_addr,
    'username': 'admin',
    'password': password,
    'port': 22,
    } 
ssh_conn = ConnectHandler(**net_device)


print ("\n\n")
print ("dir")
output = ssh_conn.send_command("dir")
print (">> " + output + '\n')
scp_conn = SCPConn(ssh_conn)
print ("Copying files...\nPlease wait for a while... \n")
scp_conn.scp_transfer_file(s_file, d_file)

When I run this in web browser, it stops here in the copying files and it gives me this error:

Error

SaschaM78
  • 4,376
  • 4
  • 33
  • 42
M Pascual
  • 55
  • 2
  • 6
  • the most likely problem is that the web browser is not running the script from the folder you think it does. If you call the script from the web server, the shell root folder is the web server's not the python script root, so when it looks for the file, it should be referenced from the web server's root folder. – MrE Jun 28 '17 at 02:48
  • check https://stackoverflow.com/questions/3718657/how-to-properly-determine-current-script-directory-in-python – MrE Jun 28 '17 at 02:49
  • @MrE I already put the .bin file into the web server root folder. still the same error. – M Pascual Jun 28 '17 at 05:40

0 Answers0