Net::FTP to ftp a file


/ Published in: Perl
Save to your folder(s)

Simple way to do ftp from Perl


Copy this code and paste it in your HTML
  1. use Carp;
  2. use Net::FTP;
  3.  
  4. my $ip = ...; # Target machine
  5.  
  6. my $local= ...; # local filename
  7. croak "$local file is missing !!\n" unless -f $local;
  8.  
  9. my $remote= ...; # Remote filename
  10.  
  11. my $ftp= Net::FTP->new( $ip
  12. ,Port => 21 # Standard port number
  13. ,Timeout => 15 # Timeout in seconds
  14. )
  15. or croak "Failed to connect to $ip.";
  16.  
  17. my $user= ...; # login user
  18. my $pw = ...; # login password
  19. $ftp->login( $user, $pw )
  20. or croak "Failed to login.";
  21.  
  22. $ftp->put( $local, $remote)
  23. or croak "Failed to ftp.";
  24.  
  25. $ftp->quit();

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.