Jump to content

downloading an archive file with ftp_get it arrive empty


jomla

Recommended Posts

He at all,
I am trying  sftp_class.php of Rachel baker
It is easy to implemet and use but it do not download .sql.gzip archive that corrupt during download.
Infact I tryed this class only to try to transfer my mysql dump backup from my web site to my local server XAMPP on windoes 10 PC.
It do not  make errors but  filles transfered are empty (0 bytes) and with the name without extension therefore windows 10 not recognize them as gzip archive.
By exemple if into web server file is named:
backup-29-5-2017--17_50.sql.gzip
locally after transfer its name is:
backup-29-5-2017-
Please, have you any idea to solve this problem?
Thank you very much

Link to comment
Share on other sites

You need to show your code if you're having problems.

One thing is that her "SFTP" class is not SFTP, it is "simple FTP".  If you're trying to use that with SFTP then that's one problem.  You should also be downloading files using binary mode, not ASCII mode.  The default for that is ASCII, so if you're not changing that then that's another problem.

Link to comment
Share on other sites

<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
ini_set('upload_max_filesize', '50M');   
ini_set('post_max_size', '50M');  
// *** Include the SFTP class
include('sftp.class.php');

//include configuration $ftp_Host, $ftp_user and $ftp_password
include('config.php');

$dir="backups";
$ftp_host=FTP_HOST;
$ftp_user=FTP_USER;
$ftp_pass=FTP_PASS;
 
// *** Create the FTP object
$ftpObj = new SFTP($ftp_host,$ftp_user,$ftp_pass);
 
// *** Connect
if ($ftpObj -> connect()) {
 echo 'connected <br>';
} else {
    echo 'Failed to connect';
}

// *** Change to folder
$ftpObj->cd('public_html/'.$dir.'/');
 
// *** Get folder contents
$contentsArray = $ftpObj->ls($ftpObj->pwd());

$fileTo = dirname(__FILE__).'/backups/';
$fileFrom =$ftpObj->pwd();

// *** Download file
for ($i=0;$i<count($contentsArray);$i++){
    if (is_dir($contentsArray[$i]))
    {continue;}
    if (substr($contentsArray[$i],-5)!==".gzip")
    {continue;}
    if ($ftpObj->get($fileFrom.'/'. $contentsArray[$i],$fileTo.$contentsArray[$i], FTP_BINARY))
    {echo "I download:".$fileTo.$contentsArray[$i]."<br>"; }
}
    $ftpObj->close();

?>

Link to comment
Share on other sites

I would print the $contentsArray out to verify what that's returning.  Note that using is_dir is not going to check on the remote server, that's looking for a directory on your local server.  As a sanity check you should also print both paths that you're passing to get.

Link to comment
Share on other sites

I tryed to use ftp functions  without to use class but now it make  following error.
 

Warning: ftp_get(): Prohibited file name: C:\xampp\htdocs\iomla\backups\dump.php in C:\xampp\htdocs\iomla\ftp0.php on line 40

$contentsArray=ftp_nlist($conn_id, "*.gzip");
Now $contentsArray return an array with all .sql.gzip files of the folder to download

Link to comment
Share on other sites

SOLVED
Error was into the archives file name because I used prohibited character ":" during mysqldump.
Script now work fine after changed sftp.class with a normal easy class

<?php

ini_set('error_reporting', E_ALL);

ini_set('display_errors', 1);

echo "<center><h1>Download SQL archives </h1></center>";

//Include configuration ftp_host, drp_user and ftp_pass

include 'ftp_config.php';

$dir="backups";

$ftp_host=FTP_HOST;

$ftp_user=FTP_USER;

$ftp_pass=FTP_PASS;

// *** Create the FTP object

$ftpObj = new FTPClient($ftp_host,$ftp_user,$ftp_pass);

// *** Connect

if ($ftpObj -> connect()) {

} else {

echo 'Failed to connect';

}

// *** Change to folder

$ftpObj->cd('public_html/'.$dir.'/');

// *** Get folder contents

$contentsArray = $ftpObj->ls('*.gzip');

 

// *** Output our array of folder contents

echo '<pre>';

print_r($contentsArray);

echo "</pre>";

 

$fileTo = dirname(__FILE__).'/backups/';

 

$fileFrom =$ftpObj->pwd();

 

// *** Download files

for ($i=0;$i<count($contentsArray);$i++){

$ftpObj->get($fileFrom.'/'. $contentsArray[$i],$fileTo.$contentsArray[$i], FTP_BINARY);

}

$ftpObj->close();

echo "<h2>Download date-timw " . date("d-n-Y h:i:s") . "<br></h2>";

?>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...