IT Community - Software Programming, Web Development and Technical Support

FTP function using PERL

This is a discussion on FTP function using PERL within the Perl forums, part of the Software Development category; hi all, i have given simple code for reading data from a file using PERL FTP Functions. eg: #!/usr/bin/...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > Perl

Register FAQ Members List Calendar Mark Forums Read
  2 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 08-27-2007, 10:37 AM
raj raj is offline
D-Web Programmer
 
Join Date: Jul 2007
Posts: 89
raj is on a distinguished road
Default FTP function using PERL

hi all,

i have given simple code for reading data from a file using PERL FTP Functions.


eg:

#!/usr/bin/perl
use Net::FTP;

my $host="test.com";
my $directory="pub";

$ftp=Net::FTP->new($host,Timeout=>240) or $newerr=1;
push @ERRORS, "Can't ftp to $host: $!\n" if $newerr;
myerr() if $newerr;
print "Connected\n";

$ftp->login("ftp","apl\@") or $newerr=1;
print "Getting file list";
push @ERRORS, "Can't login to $host: $!\n" if $newerr;
$ftp->quit if $newerr;
myerr() if $newerr;
print "Logged in\n";

$ftp->cwd($directory) or $newerr=1;
push @ERRORS, "Can't cd $!\n" if $newerr;
myerr() if $newerr;
$ftp->quit if $newerr;

@files=$ftp->dir or $newerr=1;
push @ERRORS, "Can't get file list $!\n" if $newerr;
myerr() if $newerr;
print "Got file list\n";
foreach(@files) {
print "$_\n";
}
$ftp->quit;


sub myerr {
print "Error: \n";
print @ERRORS;
exit 0;
}
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 09-05-2007, 08:00 AM
S.Vinothkumar S.Vinothkumar is offline
D-Web Genius
 
Join Date: May 2007
Posts: 1,061
S.Vinothkumar is on a distinguished road
Wink Re: FTP function using PERL

FTP is a client-server protocol. That is, there's a server which listens for connections on an agreed-upon port address (FTP uses 21 by default). Once a connection is made, the server allocates a new port for communication with the client. This leaves port 21 free to accept the connection from the next client. The client and server communicate conversationally, with the client sending commands defined in the FTP protocol to the server, and the server sending responses back to the client. This is the architecture for many well known protocols on the Internet such as SMTP, NNTP, and HTTP.

Here's an example of a conversation between an FTP server and a client. It shows what communication is necessary to connect, login, change directory and retrieve a file. The commands sent from the client to the server are shown in bold.

220 ftphost FTP server (SunOS 4.1) ready.
USER anonymous
331 Guest login ok, send ident as password.
PASS perl-journal-staff@perl.com
230 Guest login ok, access restrictions apply.
CWD pub
250 CWD command successful.
PWD
257 "/pub" is current directory.
PORT 127,0,0,1,16,110
200 PORT command successful.
RETR testfile
150 ASCII data connection for testfile (127.0.0.1,4206) (0 bytes).
226 ASCII Transfer complete.
QUIT
221 Goodbye.



For more visit the following link...

FTP: File Transfer Using Perl - The Perl Journal, Autumn 1996
__________________
S.VinothkumaR
Behind me is infinite power,
Before me is Endless Possibility,
Around me is Boundless Opportunity,
Why should I fear!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://www.discussweb.com/perl/3531-ftp-function-using-perl.html
Posted By For Type Date
Perl [Archive] - DiscussWeb IT Community - Technical Support and Technology Discussions This thread Refback 03-13-2008 01:21 PM
DiscussWeb IT Community - Technical Support and Technology Discussions This thread Refback 08-29-2007 10:10 PM

Similar Threads
Thread Thread Starter Forum Replies Last Post
what is perl? inder Perl 2 09-25-2008 04:10 AM
How will use perl function in php page? raj PHP Programming 17 08-14-2007 07:30 AM
How to set Perl Interpreter within perl script sivaramakrishnan Perl 1 07-19-2007 05:45 AM
Diff inline function and ordinary function vigneshgets C and C++ Programming 1 05-24-2007 10:34 AM
Perl? swoosh Perl 2 03-19-2007 03:31 AM


All times are GMT -7. The time now is 09:37 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0