简体   繁体   中英

Download CSV file from FTP server to save locally and process for Uploading

I need to write a PHP script that downloads a file (master.csv) from an ftp server (ftp.example.com) and prepares it for processing and uploading. I've tried this a number of times but my code is no good, I'm new to PHP. How would I go about doing this?

<?php
///vars
$local_file = 'xmitpart2.csv';
$server_file = 'master.csv';
$ftp_server="ftp.example.com";
$ftp_user="username";
$ftp_pass="paswd";

//connect to server
$conn_id = ftp_connect($ftp_server);

// login to ftp
$login_result = ftp_login($conn_id, $ftp_user, $ftp_pass);

//download $server_file and save to $local_file
if (ftp_get($conn_id, $local_file, $server_file, FTP_ASCII)) 
{
    echo "Holy Crap Finally!\n";
}
else 
{
    echo "Of Course.\n";
    //WRONGO DIE DIE DIE
    die;
}

// close the connection
ftp_close($conn_id);

You can use ftp_get();

It allows you to get a file from an FTP server and save it locally.

Once you have it saved locally you can do what ever you want to "prepare it" as you say.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM