FTP: Difference between revisions

Content added Content deleted
m (→‎{{header|Perl 6}}: re add directory change command)
m (→‎{{header|Perl}}: use a working server, cleaner code)
Line 529:
 
=={{header|Perl}}==
<lang Perlperl>use Net::FTP;
#!/usr/bin/perl
use strict;
use warnings;
use 5.020;
#This script is dependent upon the Net::FTP cpan module
use Net::FTP;
 
# set server and credentials
#Put the name of the FTP server here
my $host = "kernel'speedtest.tele2.org"net';
my $user = 'anonymous';
#Credentials go here
my $userpassword = "anonymous"'';
my $password = "";
 
#Set toconnect in passive mode
#Attempt to connect to the server using the credentials provided.
my $f = Net::FTP->new($host) or die( "Something went wrong. Can't open $host\n");
$f->login($user, $password) or die( "Something went wrong. Can't loglogin as $user in.\n");
 
#Set to passive mode
$f->passive();
 
# change remote directory, list contents
#Change to whatever directory you want. If no args are passed to cwd(), it sets it to the root directory
$f->cwd("pub/linux/kernel"'upload');
my @dirfiles = $f->ls();
#Print the current dir
printf "Currently %d files in the 'upload' directory.\n", @files;
my @dir = $f->ls();
foreach my $element (@dir)
{
say("$element");
}
 
#Download the file and store locally. get() returns the local filename
my $local = $f->get("README");
say("Your file was stored as $local in the current directory! ");
</lang>
 
# download file in binary mode
Output:
$f->cwd('/');
<pre>
$f->type('binary');
COPYING
my $local = $f->get("README"'512KB.zip');
CREDITS
say(print "Your file was stored as $local in the current directory! \n");</lang>
Historic
{{out}}
README
<pre>Currently 20 files in the 'upload' directory
SillySounds
Your file was stored as README512KB.zip in the current directory! </pre>
crypto
next
people
ports
projects
sha256sums.asc
testing
uemacs
v1.0
v1.1
v1.2
v1.3
v2.0
v2.1
v2.2
v2.3
v2.4
v2.5
v2.6
v3.0
v3.x
v4.x
Your file was stored as README in the current directory!
</pre>
 
=={{header|Perl 6}}==