在 KornShell 脚本内检查 FTP 成功/失败
想知道在 KornShell (ksh) 脚本中检查文件传输协议 (FTP) 是否成功的正确方法是什么。
Wondering what are some of the right ways to check whether File Transfer Protocol (FTP) succeeded or not inside the KornShell (ksh) script.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有如此多的 ftp 客户端,而且其中许多客户端不一定遵循 std 返回约定,因此您必须进行一些简单的测试,然后进行相应的编码。
如果幸运的话,您的 ftp 客户端确实会返回 std 退出代码,并且它们通过
man ftp
进行记录(您确实了解手册页吗?)。在这种情况下,0 表示成功,任何非零表示某种问题,因此最简单的解决方案类似于( 不太确定 ftp user@remoteHost 文件 remoteDir 是否完全正确,(我现在无法访问客户端,并且已经多年没有使用 ftp(您不应该使用 sftp!?;-)),但我在两个示例中都使用相同的内容以保持一致)。
您可能需要更多控制,因此需要捕获返回代码。
我不确定 1 或 2 的含义,这些只是说明性的。查看您的
man ftp
看看它们是否有记录,或者做一个简单的测试,故意一次向 ftp 发出一个错误,看看它是如何响应的。如果未使用 std 错误代码或不一致,那么您必须捕获 ftp 输出并检查它以确定状态,就像
我希望这会有所帮助。
There are so many ftp-clients AND many of there do not necessarily follow std return conventions that you have to do some simple tests, and then code accordingly.
If you're lucky, your ftp-client does return std exit codes and they are documented via
man ftp
(You do know about man pages?). In that case, 0 means success and any non-zero indicates some sort of problem, so the very easiest solution is something like( not quite sure that the
ftp user@remoteHost file remoteDir
is exactly right, (I don't have access to a client right now and haven't used ftp in years (shouldn't you be using sftp!? ;-) ) but I use the same in both examples to be consistent).You probably want a little more control, so you need to capture the return code.
I'm not certain about the meaning of 1 or 2, these are meant to be illustrative only. Look at your
man ftp
to see if they are documented, OR do a simple test where deliberately give one error at a time to ftp to see how it is responding.If std error codes are not used or are inconsistent, then you have to capture the ftp output and examine it to determine status, something like
I hope this helps.