如何使用Perl检查远程服务器上是否存在文件?
我可以在使用Perl模块Net :: FTP时执行此操作吗?
检查是否存在文件
if (-e $file_check) { print "File Exists!\n"; } else { print "File Doesn't Exist!\n"; }
解决方法
使用SSH执行此操作可能是最好的服务:
#!/usr/bin/perl use strict; use warnings; my $ssh = "/usr/bin/ssh"; my $host = "localhost"; my $test = "/usr/bin/test"; my $file = shift; system $ssh,$host,$test,"-e",$file; my $rc = $? >> 8; if ($rc) { print "file $file doesn't exist on $host\n"; } else { print "file $file exists on $host\n"; }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。