Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: ftp scripts

by muntfish (Chaplain)
on Aug 26, 2005 at 08:14 UTC ( [id://486823]=note: print w/replies, xml ) Need Help??


in reply to ftp scripts

As others have suggested, it is worth spending a moment checking whether you already have Net::FTP. You don't mention what OS you're on but if it's Windows and you've got ActiveState Perl installed, then Net::FTP comes as standard, so you're covered.

Having said that, it is possible to "script" the standard 'ftp' program on both Windows and Unix (thereby not worrying about sockets or RFCs). The Windows binary (ftp.exe) takes a -s command line option which specifies a file containing FTP commands. In Unix you can pipe commands in from stdin:

ftp -inv <<EOF open myhost user myuser mypassword cd somedir get afile quit EOF

That's actually a shell script solution but you could do something very similar in perl.

Hope that helps - apologies if I've missed the point.


s^^unp(;75N=&9I<V@`ack(u,^;s|\(.+\`|"$`$'\"$&\"\)"|ee;/m.+h/&&print$&

Replies are listed 'Best First'.
Re^2: ftp scripts
by muntfish (Chaplain) on Aug 26, 2005 at 10:22 UTC

    I forgot to point out that by using this method (passing a list of commands to the OS's standard FTP program) you make error-handling a whole lot more difficult. With Net::FTP you can check for errors programatically after each step, and abort as soon as something fails. With this method you end up running all the commands, even if the very first (or even the login) fails, which generates a huge pile of spurious errors. Then you need to capture the output from the ftp program (into a file, or pipe it in) then parse it for strings that look like errors - usually but not always a three-digit code at the start of a line... SFTP is even worse...

    I think I've successfully argued against my own solution - so make best efforts to find/install Net::FTP before resorting to this way!


    s^^unp(;75N=&9I<V@`ack(u,^;s|\(.+\`|"$`$'\"$&\"\)"|ee;/m.+h/&&print$&

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2024-04-23 09:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found