批量命令检查FTP连接是否成功 [英] Batch command to check if FTP connection is successful

查看:732
本文介绍了批量命令检查FTP连接是否成功的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个批处理命令来通过FTP发送数据。在发送实际数据之前,我需要查找FTP服务器是否处于活动状态。如何在批处理命令中检查它?



服务器在连接时响应220 server ready消息。

解决方案

我不认为用Windows ftp.exe 执行此操作是不可靠的。



无论连接或以前的命令是否成功,它都会盲目地继续运行命令。



它甚至不会通过退出报告结果代码。



您只需解析 ftp.exe 输出。






您应该更好地使用第三方FTP客户端。 例如 WinSCP脚本你可以使用:

  @echo off 

winscp.com /log=ftp.log/ command ^
open ftp:// user:password@example.com/^
把c:\local\path\file.txt^
exit

如果连接( 打开 命令)失败,WinSCP获胜不执行以下命令( put )。



另请参阅将Windows FTP脚本转换为WinSCP FTP脚本



(我是WinSCP的作者)


I am writing a batch command to send data via FTP. Before sending the actual data I need to find if the FTP server is active/running. How do I check that in batch command?

The server responds with "220 server ready" message when it is connected.

解决方案

I do not think there's a reliable way to do this with Windows ftp.exe.

It blindly keeps running the commands, no matter if connection or previous commands succeeded.

It won't even report the result via exit code.

All you can do is to parse the ftp.exe output.


You should better use a 3rd-party FTP client.

For example with WinSCP scripting you can use:

@echo off

winscp.com /log=ftp.log /command ^
    "open ftp://user:password@example.com/" ^
    "put c:\local\path\file.txt" ^
    "exit" 

If connection (the open command) fails, WinSCP won't execute the following commands (the put).

See also Converting Windows FTP script to WinSCP FTP script.

(I'm the author of WinSCP)

这篇关于批量命令检查FTP连接是否成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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