- 论坛徽章:
- 1
|
本帖最后由 leehunter 于 2015-07-15 10:21 编辑
这个模块是Win32::Internet模块中的FTP功能,与Net::FTP功能大同小异,但是后者在所有平台都可以用
其实就是window电脑远程登录linux服务器,自动批量下载或者上传一些东西而已,没有其它用途
[Perl]代码
use Win32::Internet;
$I = new Win32::Internet();
$host = "服务器IP地址";
$user = "用户名";
$pass = "密码0";
#第一步,登陆远程服务器
print "Doing FTP()...\n";
$handle2 = $I->FTP($FTP, $host, $user, $pass, 21, 1);#该win32对象的FTP方法,用来远程登录FTP
print "Returned from FTP()...\n";
#($n, $t) = $I->Error(); 返回值是一个数组,包括返回码和解释。
print "Error=", $I->Error(), "\n";
print $FTP->GetResponse();#这个是返回一些登陆信息
print "\n----------------------------------------\n";
#第二步,对远程ftp服务器做一些简单操作
$path = $FTP->Pwd(); print " Current directory is '$path'\n" ;#当前目录
$err = $FTP->Error();print " Error: $err\n"; #每一步都可以看看操作是否成功,都有返回码
@files = $FTP->List("*.*");print "Found $#files files.\n"; #查看该登陆用户当前目录下文件
#@files = $FTP->List("*.*", 2);
#@files = $FTP->List("*.*", 3); #另外几种查看文件列表的方式
$dir = "/tmp";$result = $FTP->Cd($dir);
$err = $FTP->Error();print "*** Error: $err\n" ;
$path = $FTP->Pwd(); print " Current directory is '$path'\n" if ! $result;
#第三步,进行一系列远程操作,每一步都有返回码,可以查看状态,了解问题出在哪里
$result = $FTP->Get("dde.zip","dde.zip");
$err = $FTP->Error();print "*** Error: $err\n" if ! $result;
#每一步都都可以用这句话来查看
$result = $FTP->Put("test.pl","test.pl");
$result = $FTP->Mkdir("internet_testing");
$result = $FTP->Rmdir("internet_testing");
$result = $FTP->Rename("test.pl", "test.xxx");
$result = $FTP->Delete("test.pl");
$result = $FTP->Del("test.xxx");
$FTP->Close(); |
|