举个例子,写一个bat脚本,一个定时发送本机E盘下文件到ftp://10.3.6.12/,程序在后台运行,程序死了自动重启,开机自动启动
时间: 2023-05-23 09:01:44 浏览: 56
以下是一个可用的bat脚本,可以满足你的需求:
@echo off
:begin
ftp -s:ftp.txt
ping -n 60 localhost >nul
goto begin
ftp.txt 文件内容如下:
open 10.3.6.12
user ftp_username ftp_password
cd /remote/directory
lcd E:\
put file_to_upload.txt
quit
上面的bat脚本使用 Windows 自带的 ftp 命令将 E:\file_to_upload.txt 文件上传到 10.3.6.12 服务器的 /remote/directory 目录下。程序会每隔 60 秒自动执行一次上传操作,即使程序崩溃也会立即自动重启。如果你想在系统启动时自动启动该程序,请将bat脚本放在启动文件夹中。
相关问题
帮我写一个Windows bat脚本 把10.10.49.62:7080 https://portal.zjfh.cn/ 写入Windows hosts文件
下面是一个可以实现你的要求的 Windows bat 脚本:
```
@echo off
set hosts_file=%windir%\system32\drivers\etc\hosts
set ip_address=10.10.49.62
set host_name=portal.zjfh.cn
echo %ip_address% %host_name% >> "%hosts_file%"
echo Hosts file updated successfully!
```
这个脚本的作用是将指定的 IP 地址和主机名添加到 Windows hosts 文件的末尾。其中:
- `%windir%\system32\drivers\etc\hosts` 是 Windows hosts 文件的路径。
- `10.10.49.62` 是要添加的 IP 地址。
- `portal.zjfh.cn` 是要添加的主机名。
你可以将上述代码复制到一个文本编辑器中,然后将文件另存为 `.bat` 扩展名的文件,如 `update_hosts.bat`。然后双击运行该脚本,它会将指定的 IP 地址和主机名添加到 Windows hosts 文件中。请注意,你需要以管理员身份运行此脚本才能修改 Windows hosts 文件。
写一个.bat脚本用来遍历指定路径下的全部文件
以下是一个遍历指定路径下所有文件的批处理脚本:
```
@echo off
setlocal enabledelayedexpansion
set search_dir=C:\path\to\search\directory
for /r "%search_dir%" %%a in (*) do (
set file_path=%%a
echo !file_path!
)
```
在上面的脚本中,您需要设置变量 `search_dir` 为要搜索的目录的路径。脚本将遍历指定目录及其子目录中的所有文件,并将每个文件的完整路径打印到屏幕上。
注意,这个脚本可能会列出非常多的文件,如果您只想列出特定类型的文件,可以修改通配符 `*` 为您需要的文件扩展名,例如 `*.txt`。