WinSCP和PuTTY在刷openwrt固件的使用教程

【openwrt必备工具】WinSCP和PuTTY的搭配与使用

PuTTY和WinSCP是管理OpenWRT固件的路由器必备工具。

WinSCP的优势在于支持多语言、可在图形化界面下管理Linux系统里的文件和存储多个会话设置以方便多设备多用户登录。PuTTY的优势在于提供与Linux终端一样的命令行控制界面。

所以,一般可先用WinSCP登录,管理文件,在必要的时候,调出PuTTY输入终端命令,实现优势互补。那既然在WinSCP中快速调用PuTTY输入终端命令是常见的事,就得让二者更好的配合,方法如下:

1.下载免安装版的WinSCP,解压至XXXWinSCP目录(XXX表示某一个目录);
2.下载需要的语言包,解压至XXXWinSCP目录;
3.下载免安装版的PuTTY,解压至XXXPuTTY;
4.运行XXXWinSCPWinSCP.exe,出现“WinSCP登录”窗口;
5.按下“Languages”按钮,选择语言;
6.勾选“高级选项”;
7.选择树状列表中的“选项”项目;
8.按下“其它通用选项”的“选项”按钮,弹出的“选项”窗口;
9.选择“选项”窗口里树状列表中的“集成-应用程序”;
10.把“PuTTY路径”改为相对路径的“..PuTTYputty.exe”(这一步是关键,路径前面的“..”表示父目录,即代表上面“XXX”目录,改成这样的好处是以后只要把XXX目录下的WinSCP和PuTTY两个目录一起移动到其它任意一个目录后,这个设置依然有效);
11.勾选“记住会话密码并传给PuTTY(SSH)”项目,点“确定”按钮返回“WinSCP登录”窗口;
12.选择树状列表中的“会话”项目;
13.在“文件协议”下拉列表框中选择“SCP”;
14.在“主机名”文本框中输入“192.168.99.1”(如意·云路由默认的IP地址);
15.在“端口号”文本框中输入“22”(OpenWRT SSH服务默认的端口);
16.在“用户名”文本框中输入“root”(OpenWRT默认的管理员账户名);
17.在“密码”文本框中输入管理员账户的密码;
18.点“保存”按钮,弹出“会话另存为”窗口;
19.在“会话另存为”文本框中输入会话名称,点“确定”按钮返回“WinSCP登录”窗口;
20.在选择树状列表中的“会话-存储的会话”项目;
21.选择会话名称,点“登录”按钮,弹出“警告”窗口;
22.按“否”按钮,弹出“WinSCP”主界面,左侧是本地目录,右侧是路由器的Linux系统目录;
23.可以在本地目录和路由器Linux系统目录间拖拽文件完成文件复制传输,在路由器的Linux系统目录的文件上按双击可以打开文件,按“Ctrl+P”快捷键(或按“命令”主菜单-“在PuTTY中打开”),弹出“PuTTY Security Alert”窗口,按“否”键钮,可直接打开PuTTY窗口并自动登录路由器的Linux终端。

刷固件:

1.1 Root无密码时: 可用HFS构建HTTP文件服务器. 如:http://192.168.1.224/wr703n-eok.bin, 然后CMD命令窗口中输入命令:
telnet 192.168.1.1
cd /tmp
wget http://192.168.1.224/wr703n-eok.bin
1.2 Root有密码时: 先将固件用winscp上传到/tmp/下或者用上面的wget命令, 然后用putty或者securecrt登陆路由器
2. mtd -r write /tmp/固件.bin firmware, 成功后会出现 rebooting…
注: dd下用 linux,openwrt下用 firmware

— mtd 源码中的相关部分:

static void usage(void)
{
    fprintf(stderr, "Usage: mtd [<options> ...] <command></command> [<arguments> ...] <device>[:<device>...]

"
    "The device is in the format of mtdX (eg: mtd4) or its label.
"
    "mtd recognizes these commands:
"
    "        unlock                  unlock the device
"
    "        refresh                 refresh mtd partition
"
    "        erase                   erase all data on device
"
    "        write <imagefile>|-     write <imagefile> (use - for stdin) to device
"
    "        jffs2write <file>       append <file> to the jffs2 partition on the device
");
    if (mtd_fixtrx) {
        fprintf(stderr,
    "        fixtrx                  fix the checksum in a trx header on first boot
");
    }
    fprintf(stderr,
    "Following options are available:
"
    "        -q                      quiet mode (once: no [w] on writing,
"
    "                                           twice: no status messages)
"
    "        -n                      write without first erasing the blocks
"
    "        -r                      reboot after successful command
"
    "        -f                      force write without trx checks
"
    "        -e <device>             erase <device> before executing the command
"
    "        -d <name>               directory for jffs2write, defaults to "tmp"
"
    "        -j <name>               integrate <file> into jffs2 data when writing an image
");
    if (mtd_fixtrx) {
        fprintf(stderr,
    "        -o offset               offset of the image header in the partition(for fixtrx)
");
    }
    fprintf(stderr,
#ifdef FIS_SUPPORT
    "        -F <part>[:<size>[:<entrypoint>]][,<part>...]
"
    "                                alter the fis partition table to create new partitions replacing
"
    "                                the partitions provided as argument to the write command
"
    "                                (only valid together with the write command)
"
#endif
    "
"
    "Example: To write linux.trx to mtd4 labeled as linux and reboot afterwards
"
    "         mtd -r write linux.trx linux

");
    exit(1);
}</part></entrypoint></size></part></file></name></name></device></device></file></file></imagefile></imagefile></device></device></arguments></options>

Opkg 是一个轻量快速的套件管理系统,目前已成为 Opensource 界嵌入式系统标准。
常用于路由、交换机等嵌入式设备中,用来管理软件包的安装升级与下载。常用命令如下:
opkg update 更新可以获取的软件包列表
opkg upgrade 对已经安装的软件包升级
opkg install 安装指定的软件包
opkg instal /tmp/xxx.ipk
opkg install http://openwrt.8800.org:82/nwan.ipk
opkg install http://openwrt.8800.org/luci-app-nwan.ipk
opkg install –force-reinstall http://192.168.1.224/uhttpd_32_ar71xx.ipk
opkg remove 卸载已经安装的指定的软件包. opkg remove luci-i18n-chinese
opkg list
opkg list-installed

Force Options:
–force-depends Install/remove despite failed dependencies
–force-maintainer Overwrite preexisting config files
–force-reinstall Reinstall package(s)
–force-overwrite Overwrite files from other package(s)
–force-downgrade Allow opkg to downgrade packages
–force-space Disable free space checks
–force-postinstall Run postinstall scripts even in offline mode
–force-remove Remove package even if prerm script fails
–noaction No action – test only
–download-only No action – download only
–nodeps Do not follow dependencies
–force-removal-of-dependent-packages
Remove package and all dependencies
–autoremove Remove packages that were installed
automatically to satisfy dependencies
-t Specify tmp-dir.
–tmp-dir Specify tmp-dir.

一般我们在openwrt下用opkg安装软件有两种:
1. 连上网络后从官方网站安装 opkg update; opkg install XXX.ipk;
opkg install http://openwrt.8800.org/luci-app-nwan.ipk
2. PC上把软件下载下来,传到路由器tmp目录安装 opkg install /tmp/XXX.ipk

对于1来说,如果路由暂时上不了网,就无法使用,方法2又有些麻烦. 这里提供的方法是:
1. 修改/etc/opkg.conf, 把里边第一行那个网址改成本地服务器放安装包的服务目录,
#src/gz snapshots http://downloads.openwrt.org/snapshots/trunk/ar71xx/packages
src/gz snapshots http://192.168.1.224/packages-r31296
2. 把相关的 packages 目录下的文件都放在上步定义的目录下(packages-r31296为目录名)
3. 在本机上用 HTS 开启http服务, 添加上面的目录
4. 现在可以像方法1一样使用升级了

工作图片如下:
这里写图片描述

版权声明:本文为博主原创文章,未经博主允许不得转载。

原文地址:https://www.cnblogs.com/yangquanhui/p/4937499.html