0

I want to create a CSV file in a remote server in a certain folder. I have the FTP details, and the code for creating the CSV ready, but my problem is I am unable to save that CSV in that remote server. I used below code to connect to FTP:

$ftp_server = "127.0.0.1";      // FTP Server Address (exlucde ftp://)
$ftp_user_name = "username";    // FTP Server Username
$ftp_user_pass = "password";    // Password

// Connect to FTP Server
$conn_id = ftp_connect($ftp_server);
// Login to FTP Server
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

Now I want to save the file to the connection made above.

Currently below is the code that i used to open a csv stream.

$structure = './orderexport/'.$order_date;
if (!mkdir($structure, 0777, true)) {
    $filename = "orderexport/".$order_date."/test_".$order_id.".csv";
} else{
    $filename = "orderexport/".$order_date."/test_".$order_id.".csv";   
}

$fp = fopen($filename, 'w');

Is there anything I need to do on csv end too to save it to remote server?

Drenmi
  • 8,492
  • 4
  • 42
  • 51
Navin Bista
  • 1,988
  • 2
  • 21
  • 37

1 Answers1

0

Just for your reference ( Code not tested , just make use of ftp_mkdir() & ftp_put() )

$ftp_server = "127.0.0.1";      // FTP Server Address (exlucde ftp://)
$ftp_user_name = "username";     // FTP Server Username
$ftp_user_pass = "password";      // Password

// Connect to FTP Server
$conn_id = ftp_connect($ftp_server);
// Login to FTP Server
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

$structure = './orderexport/'.$order_date;

if (ftp_mkdir($ftp_conn, $structure )) {

    $filename = "orderexport/".$order_date."/test_".$order_id.".csv";
    ftp_put($conn_id, $filename, $file, FTP_ASCII);
    echo 'Success';
}
else{
    echo 'Error';
}
Dimag Kharab
  • 4,439
  • 1
  • 24
  • 45