Jump to content

PHP warning: ftp_put(): Can't open data connection


sunilvadranapu

Recommended Posts

Hi, i'm trying to upload files with FTP_PUT in my PHP script. but when i run the scirpt i'm getting the warnging - PHP Warning:  ftp_put(): Can't open data connection. in /tmp/sun/test.php on line 70

 

I'm not sure why my code is failing. Below is the PHP script using to FTP files.


<?php

$ftpServer = $argv[1];
$localpath = $argv[2];
$rempath = "/home/sun/data";

$connId = ftp_connect($ftpServer);
$loginRes = ftp_login($connId, "root", "root");

if((!$connId) || (!$loginRes)){
   die("Ftp failed");
}


ftp_pasv($connId, true);
ftp_site($connId, 'UMASK 013');


if ($handle = opendir($localpath)) {
   while (($filename = readdir($handle)) !== false) {

     if (is_file("$localpath/$filename")) {
   
       if(ftp_put($connId, "$rempath/$filename", "$localpath/$filename", FTP_ASCII)){
         $rfsize = ftp_size($connId, "$rempath/$filename");

         if(function_exists('ftp_chmod')){
           ftp_chmod($connId, 0764, "$rempath/$filename");
         }
       }
    }
   }
closedir($handle);
ftp_close($connId);

?>

 

 

could anyone help me by figuring out the error in above code.

 

Thanks in advance.

 

 

I have permissions to write on target directory. moreover it is working fine when number of files to be copied in source directory is less than 1000. but when backlog count increased then FTP connection(ftp_put) was failing.

is there any mechanism to handle it in more better way.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.