>>>>> "b" == boman <shamb...@yahoo.com> writes:
b> Have a simple script to FTP all files in one dir to a Solaris box. b> Script runs fine when invoked from command line. However, when invoked b> from browser (simple html form with one button that calls the .pl b> script), only some files get FTPd. The process seems to stall, then b> the browser times out. b> Running Apache 2.2 on Windows 2003 SP2, perl 5.8.8, ftp-ing to Solaris b> 9 box. b> #!c:/Perl/bin/perl.exe b> use CGI qw/:standard/; b> use Net::FTP; b> $| = 1; b> $sourcedir = "d:\\sourcefiles"; b> $ftpdir = "/destination"; b> print header; b> print start_html('FTP'); b> $time = `time /T`; b> chomp($time); eww. get the time from perl itself with time() and localtime(). b> print h4("ftp beginning - $time"); b> ### get list of files in source directory b> opendir(DIR, $sourcedir); always check if open/opendir succeeds. maybe you are in a wrong dir in you cgi or have the wrong permissions. you can't tell here. b> @files = readdir(DIR); b> closedir(DIR); b> ### open FTP connection b> $ftp = Net::FTP->new("10.0.0.1", Debug => 1, BlockSize => 4096); b> $ftp->login("user", "pass"); b> $ftp->binary(); b> $ftp->cwd("$ftpdir"); don't quote scalars like that. not needed and can lead to bugs. b> foreach $file (@files) { b> if ($file !~ /^\./) { next if $file =~ /^\./ ; that way you can skip the block and indentation b> if ($file =~ /\.jpg$|\.xml$/) { next unless $file =~ /\.jpg$|\.xml$/ ; same here. b> $ftp->put("$sourcedir\\$file"); you can use slashes in any path in code in winblows. the backslash is only needed in their command shell. and you don't check for errors in the ftp transfer. maybe it fails and you don't know it or why. b> $time = `time /T`; b> chomp($time); again with the forking for time. and you don't even use this one anywhere. b> print p("$file ftp'd"); b> } b> } b> } b> $ftp->quit; b> $time = `time /T`; b> chomp($time); you really like that. good 'time' to learn the better way. uri -- Uri Guttman ------ u...@stemsystems.com -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Training, Support ------ --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com --------- -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/