1

I would like to a file MYFILE.csv to a remote FTP. Below is the script. The connection part works but not the file upload. I get the "There was a problem while uploading" message.

Thank you for your help.

<?php
$server = 'ftp.website.com' ;//Address of ftp server
$user_name = 'MYUSERNAME'; // Username
$password = 'MYPASSWORD'; // Password

$source_file = '/home/MYFILES.csv'; 
$dest = '/in/';

// set up basic connection
$connection = ftp_connect($server, 21) or die("Couldn't connect to     $ftp_server"); 

echo "can connect";
echo "<br />";
// login with username and password
ftp_login($connection, $user_name, $password) or die("Cannot login");
echo "can login";
echo "<br />";

  // upload a file
  if (ftp_put($connection, $dest, $source_file, FTP_BINARY)) 
 { echo "successfully uploaded \n";} 
  else
  { echo "There was a problem while uploading \n";}

// close the connection
ftp_close($connection);
?>

2 Answers 2

1

Found the solution:

?php
$server = 'ftp.WEBSITE.com' ;//Address of ftp server
$user_name = 'MYUSERNAME'; // Username
$password = 'MYPASSWORD'; // Password

$source_file = '/home/MYFILE.csv'; 
$dest = '/in/MYFILE.csv';

// set up basic connection 
$connection = ftp_connect($server, 21) or die("Couldn't connect to     $ftp_server"); 
echo "can connect";
 echo "<br />";

// login with username and password
ftp_login($connection, $user_name, $password) or die("Cannot login");
echo "can login";
echo "<br />";
// upload a file
ftp_put($connection, $dest, $source_file, FTP_ASCII) or die ("Cannot upload");

// close the connection
    ftp_close($connection);
    ?>
Sign up to request clarification or add additional context in comments.

Comments

0

i see the dest folder is "/in/".

Are you sure that its not trying to put it at the root folder of your ftp ? (Which may belongs to root user, that's would be why it fail)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.