1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#!/usr/bin/perl -w use strict; use Data::Dumper; use SPLMget; my $loginData = { gtacUsername => '', gtacPassword => '', gtacURL => 'http://ftp.ugs.com', sgtacURL => 'https://ftp.ugs.com', cookie => '' }; my @location = []; my $plm = SPLMget->new; if ($plm->login($loginData)) { $location[0] = 'tecnomatix/'; my $url = join('/', $loginData->{gtacURL}, $location[0]); my $data = $plm->readFilesAndDirs($url); }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
package SPLMget; use strict; use warnings; use Data::Dumper; use LWP::UserAgent; my $ua = LWP::UserAgent->new(); $ua->agent('Perl LWP-UserAgent'); sub login { my $class = shift; my $logindata = shift; my $response = sendGETrequest($class, $logindata->{gtacURL}); return 0 if (!$response->is_error); my $postData = 'credential_0=' . "$logindata->{gtacUsername}" .'&credential_1=' . "$logindata->{gtacPassword}" . '&destination=%2F&protocol=http'; $response = sendPOSTrequest($class, $logindata->{sgtacURL}, $postData); return 0 if (!$response->is_redirect); $class->{COOKIE} = $response->header('Set-Cookie'); $response = sendGETrequest($class, $logindata->{gtacURL}); return 1; } sub readFilesAndDirs { my $class = shift; my $loc = shift; my $items = []; my $response = sendGETrequest($class, $loc); return 0 if (!$response->is_success); my $content = $response->content; my ($h,$b) = split('<a name="top"></a>', $content); my ($table, $c) = split('<a href="#top">', $b); my @rows = $table =~ /\<tr\>(.+?)\<\/tr\>/gs; foreach my $row (@rows) { $row =~ s/\n//g; next if ($row !~ /\<td/); my ($dummy, $path, $type, $date, $link, $linkDesc) = undef; ($dummy, $path, $type, $date) = $row =~ /\<td(?:.*?)\>(.*?)\<\/td\>/g; if (defined $path) { next if ($path =~ /\.\./); ($link, $linkDesc) = $path =~ /^\<a href\=\"(http(?:.+?))\"\>(\w+)\/\<\/a\>$/; if (defined $link) { if ($type eq 'Directory') { $type = 1; } else { $type = 0; } my $item = { DATE => $date, isDIR => $type, LINK => $link, DESCRIPTION => $linkDesc }; push $items, $item; } } } print Dumper $items; return $items } sub sendGETrequest { my $class = shift; my $url = shift; my $getRequest = HTTP::Request->new(GET => $url); $getRequest->push_header('Accept-Encoding' => 'gzip, deflate'); $getRequest->push_header('Connection' => 'keep-alive'); $getRequest->push_header('Accept' => 'image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*'); $getRequest->push_header('Cookie' => $class->{COOKIE}) unless ($class->{COOKIE} eq ''); my $response = $ua->request($getRequest); return $response; } sub sendPOSTrequest { my $class = shift; my $url = shift; my $postData = shift; my $postRequest = HTTP::Request->new(POST => $url); $postRequest->content_type('application/x-www-form-urlencoded'); $postRequest->push_header('Accept-Encoding' => 'gzip, deflate'); $postRequest->push_header('Connection' => 'keep-alive'); $postRequest->push_header('Accept' => 'image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*'); $postRequest->content($postData); my $response = $ua->request($postRequest); return $response; } sub new { my $class = shift; my $self = bless {}, $class; $self->{COOKIE} = ''; return $self; } 1;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$VAR1 = [
{
'LINK' => 'http://ftp.ugs.com/tecnomatix/CAD_Translators/',
'isDIR' => 1,
'DATE' => '2009-07-15 12:07:23',
'DESCRIPTION' => 'CAD_Translators'
},
{
'LINK' => 'http://ftp.ugs.com/tecnomatix/Machining_Line_Planner/',
'isDIR' => 1,
'DATE' => '2008-08-18 06:44:54',
'DESCRIPTION' => 'Machining_Line_Planner'
},
...
];
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
$VAR1 = [
{
'LINK' => 'http://ftp.ugs.com/tecnomatix/CAD_Translators/',
'isDIR' => 1,
'DATE' => '2009-07-15 12:07:23',
'DESCRIPTION' => 'CAD_Translators',
'FOLDER' => [
{
'LINK' => linkZuUnterverzeichnis,
'isDIR' => 1,
'DATE' => Zeitstempel,
'DESCRIPTION' => Beschreibung,
'FOLDER' => [Inhalt Unterverzeichnis]
},
{
'LINK' => linkZuDatei1,
'isDIR' => 0,
'DATE' => Zeitstempel,
'DESCRIPTION' => Beschreibung,
},...
]
},
];
1 2 3 4 5 6 7 8 9 10
sub read_all { return read_recursiv($_[0]); } sub read_recursiv { my $url=shift; my $list=$plm->readFilesAndDirs($url); for(@$list) { $_->{FOLDER} = read_recursiv($_->{LINK}) if($_->{isDIR}); } return $list; }