Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Image upload

by beebware (Pilgrim)
on May 03, 2002 at 22:00 UTC ( [id://163934]=note: print w/replies, xml ) Need Help??


in reply to Image upload

You might find this subroutine that I wrote of us. It's currently being run as a cronjob on one of our servers and just transfers files via FTP to another site...
use Net::FTP; $screen=1; # change to 0 for 'quiet' operation (ie no screen display) sub move_files { # moves a file by FTP to a remote site # Code by Richard Chiswell # http://www.beebware.com/ # Free usage, acknowledgements would be appreciated tho! my ($destination,$file)=@_; # destination is in the format username:password@ftp.example.com # file is the local full path name of the file to be transfered my ($username,$password,$host,$path,$ftp); my ($results,$logfile,$movedlog); # first let's split the destination information apart $destination=~/^([^\:]+)\:([^\@]+)\@([^\/]+)\/(.*)/; ($username,$password,$host,$path)=($1,$2,$3,$4); $path="/".$path; print "Destination:$destination\n" if $screen; print "Login as $username (password: $password) onto:\n" if $screen; print " Host: $host\n" if $screen; print " Path: $path\n" if $screen; $logfile.="Login as $username (password: $password) onto:\n"; $logfile.=" Host: $host\n Path: $path\n"; $logfile.=" Time: ".&show_time(time())."\n\n"; if (length($host)>1) { $ftp=Net::FTP->new($host,Debug=>0); if (!defined($ftp)) { print "* Unable to connect to FTP server:\n $@\n" if $screen; $logfile.= "*********************************************\n"; $logfile.="* UNABLE TO CONNECT TO FTPSERVER! *\n"; $logfile.="$@\n"; } else { $logfile.="Connected\n"; $results=$ftp->login($username,$password); if (!$results) { print "* Unable to login to FTP server:\n" if $screen; print $ftp->message()."\n" if $screen; $logfile.="********************************************\n"; $logfile.="* UNABLE TO LOGIN TO FTP SERVER! *\n"; $logfile.=$ftp->message()."\n"; } else { print "Logged in\n" if $screen; $logfile.="Successfully logged in\n"; $ftp->cwd($path); print "Changed to $path\n ".$ftp->message()."\n" if $screen; print "Current path is ".$ftp->pwd()."\n" if $screen; $logfile.="Path: ".$ftp->pwd()."\n"; $ftp->hash(1024); $ftp->binary(); $results=$ftp->put($file); if (!$results) { print "* Unable to transfer: file\n" if $screen; print $ftp->message()."\n" if $screen; $logfile.="* Unable to transfer:$file\n"; $logfile.=" Message:".$ftp->message()."\n"; } else { $movedlog.="Moved $file\n";unlink $file; $logfile.="Moved $file\n"; } $ftp->quit; } } $movedlog="These files have been moved to\n"; $movedlog.="$destination\n\n$movedlog\n"; } else { print "Unable to read FTP details!\n" if $screen; } return "$movedlog\n\n*****************************\n\n$logfile"; print "DONE!\n" if $screen; }
So for example, to transfer the file /temp/file.txt to ftp.example.com with the login username of 'user' and the password 'pass', just call $log=&move_files("user:pass@ftp.example.com","/temp/file.txt");. The $log can then be either emailed (as we have set it up) or just stored in a log file or disgarded. I hope it helps.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-26 06:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found