如何捕捉批处理脚本的FTP错误code? [英] How to capture the ftp error code in batch scripts?

查看:195
本文介绍了如何捕捉批处理脚本的FTP错误code?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有点关系,但不同的问题<一href=\"http://stackoverflow.com/questions/7158189/batch-file-not-accepting-parameter-in-the-form-of-1-2\">here.

I have a somewhat related, but different questions here.

我有一个批处理脚本( *蝙蝠文件)。像这样的:

I have a batch script (*.bat file) such as this:

@ftp -i -s:"%~f0"&GOTO:EOF
open ftp.myhost.com
myuser
mypassword
!:--- FTP commands below here ---
lcd "C:\myfolder"
cd  /testdir
binary
put "myfile.zip"
disconnect
bye

基本上,这是上传一个zip文件到FTP站点的脚本。我的问题是,上传操作可以从时间无法时间(远程FTP不可用,myfile.zip是不存在的,上传操作中断和诸如此类的东西),而当这种不幸的事情发生,我希望我的蝙蝠文件返回1(退出1 )。

这将是巨大的,如果我上传的不是成功,FTP将抛出一个异常(是的,就像在C ++异常),我也有将其捕获并捕获所有异常出口1 ,但我不认为这是批处理脚本可用。

It would be great if my upload wasn't successful, the ftp would throw an exception ( yes, like exception in C++), and I would have a catch-all exception that catches it and then exit 1, but I don' think this is available in batch script.

什么是做什么,我需要在这里的最好方法是什么?

What is the best way to do what I need here?

推荐答案

您可以将输出重定向到一个日志文件,当FTP会话结束后的文件可以被解析。

You can redirect the output to a log file and when the ftp session is finished the file can be parsed.

@ftp -i -s:"%~f0" > log.txt & GOTO :parse
open ftp.myhost.com
myuser
mypassword
!:--- FTP commands below here ---
lcd "C:\myfolder"
cd  /testdir
binary
put "myfile.zip"
disconnect
bye

:parse
for /F "delims=" %%L in (log.txt) Do (
  ... parse each line
)

这篇关于如何捕捉批处理脚本的FTP错误code?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆