parse-netrc.pl
资源名称:FTP总集.rar [点击查看]
上传用户:tjfeida
上传日期:2013-03-10
资源大小:1917k
文件大小:2k
源码类别:
Ftp客户端
开发平台:
Visual C++
- #!/usr/bin/perl -w
- # Brian Masney <masneyb@gftp.org>
- my ($host, $user, $pass, $account, $descr, %bmhash);
- use strict;
- open NRC, "<.netrc" or die "Can't open .netrc: $!n";
- open BM, "+>>.gftp/bookmarks" or die "Can't open .gftp/bookmarks: $!nTry running gFTP once to create a default bookmarks filen";
- seek (BM, 0, 0);
- while (<BM>)
- {
- ($descr) = /[(.*?)]/;
- next if !defined ($descr);
- $bmhash{$descr} = 1;
- }
- seek (BM, 0, 2);
- while (<NRC>)
- {
- if (/machine /)
- {
- print_bookmark ();
- ($host) = /machine (.*?)s+/;
- }
- if (/login /)
- {
- ($user) = /login (.*?)s+/;
- }
- if (/password /)
- {
- ($pass) = /password (.*?)s+/;
- }
- if (/account /)
- {
- ($account) = /account (.*?)s+/;
- }
- }
- print_bookmark ();
- close NRC;
- close BM;
- print "The contents of your .netrc file should now be stored in .gftp/bookmarksn";
- sub print_bookmark
- {
- my $i;
- return if !defined ($host);
- if (!defined ($bmhash{$host}))
- { $descr = $host; }
- else
- {
- for ($i=0; ; $i++)
- {
- $descr = "$host ($i)";
- last if !defined ($bmhash{$descr});
- }
- }
- print BM "[$descr]n";
- print BM "hostname=$hostn";
- print BM "port=21n";
- print BM "protocol=FTPn";
- print BM "remote directory=n";
- print BM "local directory=n";
- if (!defined ($user))
- { $user = "anonymous"; }
- print BM "username=$usern";
- if ($user eq "anonymous" || !defined ($pass))
- { $pass = "@EMAIL@"; }
- print BM "password=$passn";
- if (!defined ($account))
- { $account = ""; }
- print BM "account=$accountnn";
- print "Added $descr = $user@$hostn";
- undef ($host);
- undef ($user);
- undef ($pass);
- undef ($account);
- }