I'm a newbie and this is my attempt at writing a transportable subroutine that will FTP a file to a remote location. I couldn't figure out how to check for errors on the remote host, so anyone that wants to help me out, please do so ...
############################################################ # FTP_FILE - Send a file to FTP host # Requires: use Net::FTP; # Perl module for FTP access # Arguments: $sendFile - file to be sent (full path) # $name - file to be named on remote server # $host - FTP host name (ftp.japh.org) # $user - FTP login user name # $pass - FTP login password # Returns: none ############################################################ sub ftp_file { local ($sendFile, $name, $host, $user, $pass) = @_; # Pass file +name to send $ftp = Net::FTP->new($host); # Open the host $ftp->login($user,$pass); # Username and password $ftp->put($sendFile, $name); # Send the file, rename $ftp->quit; # Quit } ####################### END SUBROUTINE #####################

Replies are listed 'Best First'.
Re: Simple FTP
by mikeB (Friar) on Jul 11, 2001 at 01:52 UTC
    Those Net::FTP methods return values which indicate success or failure. Check the documentation that comes with the module for details. You probably want to do something like
    $ftp->get($file) or die "Can't get $file\n";
    for each method invocation.
Re: Simple FTP
by Cirollo (Friar) on Jul 11, 2001 at 18:27 UTC
    You don't want to be using local here; you should use my to declare your variables instead.

    my creates a lexically scoped variable - one that is only visible in the block in which it was declared.

    local creates a temporary local copy of a global variable, and this copy is visible to subroutines you call inside your block (when you use my, the variable is -not- visible to called subs).

    Generally, you want to use my rather than local.

    See also: