PHP Get Download file from FTP

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
jlpinheiro
New php-forum User
New php-forum User
Posts: 1
Joined: Mon Nov 06, 2017 1:02 pm

Mon Nov 06, 2017 1:11 pm

Hello
Have been around a PHP script to download a file from ftp
it even writes file in local but never writes file content
I have been around this for hours now
already triping
what I am doing wrong?

Code: Select all


<?php

// FTP server details
$ftpHost   = 'ftp.domain.com';
$ftpUsername = 'user1234';
$ftpPassword = 'pass1234';

// open an FTP connection
$connId = ftp_connect($ftpHost) or die("Couldn't connect to $ftpHost");

// try to login
if(@ftp_login($connId, $ftpUsername, $ftpPassword)){
    echo "Connected as $ftpUsername@$ftpHost";
}else{
    echo "Couldn't connect as $ftpUsername";
}

// local & server file path
$localFilePath  = 'test.txt';
$remoteFilePath = 'test.txt';

// try to download a file from server
if(ftp_get($connId, $localFilePath, $remoteFilePath, FTP_BINARY)){
    echo "File transfer successful - $localFilePath";
}else{
    echo "There was an error while downloading $localFilePath";
}

// close the connection
ftp_close($connId);

?>


User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 525
Joined: Mon Feb 22, 2016 5:52 pm

Tue Nov 07, 2017 10:46 am

What errors are you getting?

Post Reply