0
\$\begingroup\$

i have this php Script:

function GetFTPFile($iFile) {
        echo '<pre>';
        $StartTime   = microtime(true);
        $FTP         = [];
        $FTP['SMG']  = '';
        $FTP['st']   = 0;
        $FTP['time'] = 0;
        $nuevo_path  = $iFile['lfile'];
        $remote      = $iFile['sfile'];
        echo $P_Path      = 'ftp://' . FTP_USER . ':' . FTP_PASSWORD . '@' . FTP_HOST . $remote;
        echo '<br>';
        $FTP['test'] = $P_Path;
        $result      = file_exists($P_Path);
        if ($result == true) {
            $resultfile = copy($P_Path, $nuevo_path);
            if ($resultfile == true) {
                $FTP['SMG'] = 'Copy Successfull';
                $FTP['st']  = 1;
            } else {
                $FTP['SMG'] = 'Copy Fail!!!';
                $FTP['st']  = 0;
            }
        } else {
            $FTP['SMG'] = 'Conection Error!!!';
            $FTP['st']  = 0;
        }
        $EndTime     = microtime(true);
        echo 'Copy time via FTP: <br>';
        echo $FTP['time'] = $EndTime - $StartTime;
        echo '</pre>';
        return $FTP;
    }

and this create a FTP URI Like this

ftp://user:secretpass@xxx.xxx.xxx.xxx/dir1/dir2/repository/test.txt

And try to copy a txt File around 85 Kb from the FTP Server (UNIX) to local Disk (Linux Ubuntu Server 18.04)

the issues is that this is taken around 20 second to run the script over the file with the native function copy().

i try to make the connection over FTP client Filezilla to get the log and get this, i dont know if its relation to this:

11:16:08 Status: Connecting to xxx.xxx.xxx.xxx:21 ... 
11:16:08 Status: Connection established, waiting for the welcome message ...
11:16:22 Status: Server not secure, does not support FTP over TLS. 
11:16:22 Status: The server does not allow non-ASCII characters.**
11:16:22 Status: Registered at 
11:16:22 Status: Retrieving the directory listing ... 
11:16:22 Status: Directory "/ usr / intlu" listed correctly

which is what I am omitting, how can I decrease this delay or how to solve it?

\$\endgroup\$
  • \$\begingroup\$ You're asking why the native function copy() takes a long time to copy a file from a FTP server to your local disk. You're not really asking us to review your code. The first thing I would do is to use another FTP client, and check how long it takes to connect, login and download the file with that. The FTP server might just be slow. Alternatively you could use the normal FTP functions of PHP. Here the steps are not combined into one wrapper and can be timed separately, so you can see what takes so long. \$\endgroup\$ – KIKO Software Jul 24 '19 at 19:22
  • \$\begingroup\$ @KIKOSoftware I see that you have not read the post, I clearly place the example using Filezilla as an alternative test client and log data. \$\endgroup\$ – walter nuñez Jul 24 '19 at 20:43
  • \$\begingroup\$ Yes, I missed the relevance of that. How long does it take with Filezilla? Including the download? I still hope my comment can be useful to you. \$\endgroup\$ – KIKO Software Jul 24 '19 at 20:52
  • \$\begingroup\$ @KIKOSoftware According to the log i have put in the post, downloading files is immediate, but according to the log, at the time of logging in there is a delay in tls checking. \$\endgroup\$ – walter nuñez Jul 24 '19 at 21:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.