失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > window通过bat脚本调用WinSCP上传文件到linux服务器

window通过bat脚本调用WinSCP上传文件到linux服务器

时间:2022-07-06 17:59:56

相关推荐

window通过bat脚本调用WinSCP上传文件到linux服务器

-08-15

最近在使用 WinSCP put 文件夹时,发现很多大的临时文件,隐藏文件都上传了上去,导致上传时长超长,于是希望对上传的文件进行过滤,具体的指令可参考如下链接:

put command :: WinSCP/eng/docs/scriptcommand_put?ver=5.19.6&lang=0804&utm_source=winscp&utm_medium=app&utm_campaign=5.19.6#filemask如果不想查看文档,可开启WinSCP.exe 客户端,进行相关设置后将脚本代码拷贝出来,放在脚本文件中即可。 话不多说,直接截图:

1. 建立默认的过滤设置: “选项” -> "传输" ,选择默认 或者 添加一个新的,->"编辑"->“其他"框中选择 ”编辑”

2. 拷贝脚本代码:

文件上传界面,右键选择需要上传的文件夹 ,点击 ”上传“->"上传",再右键点击“传输设置”(此时也可进行第一步的操作), 在弹出窗中选择“生成代码”, 即可得到执行的脚本代码。

put指令后携带 -filemask="过滤文件",-rawtransfersettings[1] ExcludeHiddenFiles=1 为过滤隐藏文件

3.找到规律后,可制作成批处理文件,动态生成 put 和 get 脚本进行操作。

-04-19

看完如下操作后,想了解一下如何将参数 从uploadTest.bat 传入到test.txt 中呢? 这样就可以动态的创建修改创建的文件,我想到的办法是 在 bat 中 自动生成一个 文件, 还有其他方法么?

=====================================================================

借助转载内容后, 先是用 UE 编辑保存后,执行不成功,解决方法如下:

1. 首先在命令行下输入了:cd C:\Program Files (x86)\WinSCP 后进入 WinSCP 的安装目录。

2. 执行 help 命令: WinSCP.exe /help, 核实了 相应的指令没有错。

3. 在命令行下执行: WinSCP.exe /console, 进入工程模式,无错;

4. 在命令行下执行: /script=D:\Task\WinScp\put.txt, 以工程模式执行 命令行,发现打印信息如下:

No mapping for the Unicode character exists in the target multi-byte code page

文件必须是UTF-8或UTF-16编码格式

遂发现是txt 文件格式编码格式的原因导致。使用 windows 自带的文本编辑器重新写了一下命令,正确执行。

---------------------------------------------------------------------------------------------------------------------

批处理很强大,但是报错的时候需要注意,可以使用 /log 查看相关的日志

/log=log.log

WinSCP 中使用到的命令如下:

WinSCP 实现批处理同步文件 - 简书 ()/p/ff719480e0ef命令拷贝,所以与 put 对应的是 get, synchronize 是不是更好

命令 描述Command Descriptioncall Executes arbitrary remote shell commandcd Changes remote working directorychecksum Calculates checksum of remote filechmod Changes permissions of remote fileclose Closes sessioncp Duplicates remote fileecho Prints message onto script outputexit Closes all sessions and terminates the programget Downloads file from remote directory to local directoryhelp Displays helpkeepuptodate Continuously reflects changes in local directory on remote onelcd Changes local working directorylls Lists the contents of local directoryln Creates remote symbolic linklpwd Prints local working directoryls Lists the contents of remote directorymkdir Creates remote directorymv Moves or renames remote fileopen Connects to serveroption Sets or shows value of script optionsput Uploads file from local directory to remote directorypwd Prints remote working directoryrm Removes remote filermdir Removes remote directorysession Lists connected sessions or selects active sessionstat Retrieves attributes of remote filesynchronize Synchronizes remote directory with local one

========================================================================

以下为转载第一篇帖子内容,并进行了部分编辑:

window通过bat脚本上传文件到linux。 - 王再壮的个人空间 - OSCHINA - 中文开源技术交流社区最近帮前端做点 需求。每次更新打包后 ,都要去服务器上替换。就搞了一个。脚本直接执行,上传到服务器。 通过winscp命令上传,先安装winscp客户端。 操作步骤。 1:首先新建在d盘下新建test.txt文件,用以写入命.../u/2331292/blog/1924780通过winscp命令上传,先安装winscp客户端。

操作步骤。

1:首先新建在d盘下新建test.txt文件,用以写入命令。文件内容如下。

echo 连接远程服务器# open scp://用户名:密码@服务器地址open scp://userName:password!@ip地址或域名#本地文件/文件夹传输到服务器; 从服务器拷贝则使用 getput C:\workspace /app/www/ClientUpdate -filemask="*.txt; *.log;" -rawtransfersettings[1] ExcludeHiddenFiles=1closeexit

2:然后新建uploadTest.bat文件,通过cd命令进入到 winscp安装路径下。

# 进入到winscp安装路径下 cd D:\安装软件\WinSCP # 执行linux命令 WinSCP.exe /console /script=D:\test.txt

3:windows下双击打开uploadTest.bat文件。

如果觉得《window通过bat脚本调用WinSCP上传文件到linux服务器》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。