Hotline is a software platform for file sharing (not peer to peer). It attracts more of an “underground” community, which saw it as an easier to use successor to the Internet Relay Chat (IRC) community. This article introduces the Perl hotline client module and explains how to use it to implement a basic hotline bot that connects to a hotline server and performs a few basic operations.
Net::Hotline::Client is a class implementing a Hotline internet client in Perl. It was specifically developed to aid in the creation of Hotline “bots,” although it's suitable for most other tasks as well. Hotline is an internet client/server system that's sort of a cross between IRC and a BBS.
To install the module, you can use CPAN as follows:
$cpan >cpan get Net::Hotline::Client >cpan make Net::Hotline::Client >cpan install Net::Hotline::Client >cpan quit
If you are not using the system wide cpan repository, you can tell perl the location of the installed module using the PERL5LIB environment variable.
If you are using bash, you will need to issue a command like this :
export PERL5LIB=/path/to/home/dir/lib/perl5/site_perl/5.8.7
The following scripts uses the Net::Hotline::Client module to list all files in a given hotline server.
#! /usr/bin/perl use Net::Hotline::Client; $hlc = new Net::Hotline::Client; $hlc->connect("82.108.12.9"); $hlc->login(Login => "guest", Password => "guest", Nickname => "--nick", Icon => 128); sub print_tree { my ($dir)=@_; print $dir."\n"; # Ex: "Uploads:Pictures" $hlc->blocking_tasks(1); # Set blocking / nonblocking # Contact the server to obtain the list of files $hlc->get_filelist($dir) || return; $content = $hlc->files(); # Get reference to the file tree foreach $item (@{$content->{$dir}}) { if ($dir) { $fullpath=$dir.':'.$item->name; } else { $fullpath=$item->name; } print_tree($fullpath); } } print_tree("");
| Function | Description |
|---|---|
| downloads_dir PATH | Sets the directory where downloaded files are placed to PATH (if present). Returns the current setting. |
| get_file PATH | Download the file on the server located at PATH to the local directory set via downloads_dir() |
| get_file_resume PATH | Resume downloading the file on the server located at PATH to the local directory set via downloads_dir(). The partially downloaded file(s) must exist in the local download directory |
| recv_file TASK, REF, SIZE | Starts receiving the file designated by the Net::Hotline::Task object TASK, the download reference number REF, and the size in bytes SIZE returned by get_file() |
Example :
downloads_dir ("/tmp"); ($task, $ref, $size) = $hlc->get_file("Folder1:file.jpeg"); /* If resuming file download : ($task, $ref, $size) = $hlc->get_file_resume("Folder1:file.jpeg");*/ $hlc->recv_file($task, $ref, $size);
| Function | Description |
|---|---|
| put_file SRC_PATH, DEST_PATH, COMMENT | Upload the file located at SRC_PATH to the server directory DEST_PATH, with the file comments COMMENT. SRC_PATH must be in the native path format of the local system (i.e. using ”:” as the path separator on Mac OS, and ”/” on most other OSes). DEST_PATH must be in Hotline's native path format (”:” as the path separator) |
| put_file_resume SRC_PATH, DEST_PATH, COMMENT | Resume uploading the file located at SRC_PATH to the server directory DEST_PATH, with the file comments COMMENT |
| send_file TASK, REF, SIZE, RFLT | Starts sending the file designated by the Net::Hotline::Task object TASK, the upload reference number REF, the size in bytes SIZE, and the resume information RFLT returned by put_file(). Returns 1 if the upload completed successfully, or undef if there was an error. |
Example :
($task, $ref, $size) = $hlc->put_file("/home/john/file.gz", "Folder1:Folder2", "A fun file!"); /* If resuming an upload ($task, $ref, $size, $rflt) = $hlc->put_file_resume("/home /john/file.gz", "Folder1:Folder2", "A fun file!");*/ $hlc->send_file($task, $ref, $size);
For more details about the perl hotline module check the online documentation from CPAN.
| Labels: services, unix |
|