in reply to perl: FTP using cgi not working but FTP s/w works well

FTP uses two connections, one for commands/control and one for data (ports 21 and 22 I believe). Where in your script does the error message occur? At login? Prior to attempting the "put" for the file? "Can't open data connection" sounds like a connectivity/port issues. When you ftp files to the remote server on the command line, are you using passive mode there? Maybe try turning off passive mode and see if it makes a good data connection. What sort of troubleshooting have you already done with this? Give us some ideas of what you've tested so far, and folks can probably help point you in the right direction.

---
echo S 1 [ Y V U | perl -ane 'print reverse map { $_ = chr(ord($_)-1) } @F;'
Warning: Any code posted by tuxz0r is untested, unless otherwise stated, and is used at your own risk.

  • Comment on Re: perl: FTP using cgi not working but FTP s/w works well

Replies are listed 'Best First'.
Re^2: perl: FTP using cgi not working but FTP s/w works well
by need_help21 (Novice) on Nov 21, 2007 at 03:13 UTC
    The error i believe occurs at the place prior to attempting the "put" command. Even the turning off the Passive mode (by removing $ftp-> pasv() from the code) doesn't work and result is same. The file that was supposed to be transferred is created at the destination while executing this code but with ZERO bytes and no data is transferred. I even tried to connect the remote machine manually (instead of CGI code), i am able to login, but the file is not getting transfered. But strange to me that while using a software (Filezilla) i am able to FTP the files easily.
      As a few of us said in the CB, you're likely suffering from the ftp-data port being blocked (incoming to your web server), combined with the FTP server not implementing PASV. If that's true nothing you change in your code will make it work.

      Even if your desktop PC receives ftp-data connections OK, that's no reason to believe that your network administrator has allowed the same for the web server.

      Either have your network administrator sort it out, or use another protocol. (eg: scp, webdav, rsync, etc)

      -David

      As erroneouBollock noted, you need to bring this up with your administrator, I wasn't aware this had been brought up in the CB. If ftp'ing from your script and the command line don't work, I don't think using Filezilla would make a difference. Try using 'scp' to get the file their instead if ftp isn't working for you:
      $ scp -C localfile username@remotemachine:/remote/file/location/

      ---
      echo S 1 [ Y V U | perl -ane 'print reverse map { $_ = chr(ord($_)-1) } @F;'
      Warning: Any code posted by tuxz0r is untested, unless otherwise stated, and is used at your own risk.