Jump to content

FTP


wiggst3r

Recommended Posts

Hi

 

I'm trying to dowload a file from my FTP site to my local machine and i keep getting errors.

 

I'm using the following code:

 

$local_file = '/Users/mac/workspace/folder_test/' . $last_file;
$server_file = '/folder_name/' . $last_file;

// 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_BINARY)) {
    echo "Successfully written to $local_file\n";
} else {
    echo "There was a problem\n";
}

// close the connection
ftp_close($conn_id);

 

The file I'm looking for is in the the folder, 'folder_name' on the ftp server and I'm trying to download it to my workspace on my mac.

 

I get the following errors:

 

Warning: ftp_get(/Users/mac/workspace/folder_test/File.txt) [function.ftp-get]: failed to open stream: No such file or directory in /Users/mac/workspace/folder_test/index.php on line 40

 

Warning: ftp_get() [function.ftp-get]: Error opening /Users/mac/workspace/folder_test/File.txt in /Users/mac/workspace/folder_test/index.php on line 40

There was a problem

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/111132-ftp/
Share on other sites

 

 

wiggst3r,

 

I ran your code with the following and it worked perfectly.

 

check the leading slashes on your file defs...

 

 

<?php
$local_file = 'images/' . 'ZOS.txt'; // a folder off of document_root
$server_file = '/PUDATA/' . 'ZOS.DASD.USAGE.BY.APPLICATION.TXT'; // a folder off of FTP_ROOT
$ftpServer = '123.456.789.123';
$ftpUserName = 'Me';
$ftpUserPass = 'MyPW';
// set up basic connection
$conn_id = ftp_connect($ftpServer);
// login with username and password
$login_result = ftp_login($conn_id, $ftpUserName, $ftpUserPass);

/* then the rest of your code un changed... */
?>

Link to comment
https://forums.phpfreaks.com/topic/111132-ftp/#findComment-570447
Share on other sites

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.