Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Simple FTP

by rHOnDO (Initiate)
on Jul 10, 2001 at 21:51 UTC ( [id://95382]=CUFP: print w/replies, xml ) Need Help??

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:

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://95382]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-23 07:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found