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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.