FTP: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (→{{header|Perl 6}}: re add directory change command) |
SqrtNegInf (talk | contribs) m (→{{header|Perl}}: use a working server, cleaner code) |
||
Line 529: | Line 529: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
<lang |
<lang perl>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 = |
my $host = 'speedtest.tele2.net'; |
||
my $user = 'anonymous'; |
|||
#Credentials go here |
|||
my $ |
my $password = ''; |
||
my $password = ""; |
|||
⚫ | |||
#Attempt to connect to the server using the credentials provided. |
|||
my $f = Net::FTP->new($host) or die |
my $f = Net::FTP->new($host) or die "Can't open $host\n"; |
||
$f->login($user, $password) or die |
$f->login($user, $password) or die "Can't login as $user\n"; |
||
⚫ | |||
$f->passive(); |
$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( |
$f->cwd('upload'); |
||
⚫ | |||
#Print the current dir |
|||
printf "Currently %d files in the 'upload' directory.\n", @files; |
|||
⚫ | |||
foreach my $element (@dir) |
|||
{ |
|||
say("$element"); |
|||
} |
|||
#Download the file and store locally. get() returns the local filename |
|||
⚫ | |||
⚫ | |||
</lang> |
|||
# download file in binary mode |
|||
Output: |
|||
$f->cwd('/'); |
|||
<pre> |
|||
$f->type('binary'); |
|||
COPYING |
|||
⚫ | |||
CREDITS |
|||
⚫ | |||
Historic |
|||
{{out}} |
|||
README |
|||
<pre>Currently 20 files in the 'upload' directory |
|||
SillySounds |
|||
⚫ | |||
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 |
|||
⚫ | |||
</pre> |
|||
=={{header|Perl 6}}== |
=={{header|Perl 6}}== |