Jump to content

ftp_get cant find the file on remote server


Peggy

Recommended Posts

I'm trying to down load a file from the server to my local files. I keep getting the error that says the file can't be found.

But I know it is there. I'm sure it is just a small thing wrong in my code, but I can't seem to figure it out. I got this code off of php.net and then tweaked it a little. The code with  realpath('get_file.php') and $directory = dirname($real_path); is mine.

 

Here is my code:

 

<?php

$real_path = realpath('get_file.php');

$directory = dirname($real_path);

 

// define some variables

 

$server_file = $directory.'/'.date('m-d-y',time()).".txt";

$local_file = 'local_file_'.date('m-d-y',time()).".txt";

 

 

$ftp_server = 'example.com';

$ftp_user_name = 'myname';

$ftp_user_pass = 'mypassword';

// set up basic connection

$conn_id = ftp_connect($ftp_server);

 

// login with username and password

$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

 

// try to download $server_file and save to $local_file

if (ftp_get($conn_id, $local_file, $server_file, FTP_ASCII)) {

    echo "Successfully written to $local_file\n";

} else {

    echo "There was a problem\n";

}

 

// close the connection

ftp_close($conn_id);

?>

Would really appreciate help

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.