Guide on transferring CSV files from a different server to my server via an FTP connection

Hey there, I'm trying to figure out how to download CSV files from a folder located on the root directory of one server to another server using FTP connection. I've included the code below, but unfortunately it's not working for me. The FTP connection is established and all files are listed when using ftp_nlist command. Can someone please assist me in downloading files from one server folder to another server folder?

$ftpHost   = 'ftp.site.in';
$ftpUsername = 'username';
$ftpPassword = '******';

// open an FTP connection
$connId = ftp_connect($ftpHost) or die("Couldn't connect to $ftpHost");

// log in
if(@ftp_login($connId, $ftpUsername, $ftpPassword)){
    echo "Connected as $ftpUsername@$ftpHost";
}else{
    echo "Couldn't connect as $ftpUsername";
}
$contents = ftp_nlist($connId, ".");
var_dump($contents);
// file paths
$localFilePath  = 'csv';
$remoteFilePath = 'public_html/csvfiles/';
// download a file 
if(ftp_get($connId, $localFilePath, $remoteFilePath, FTP_BINARY)){
    echo "File transfer successful - $localFilePath";
}else{
    echo "There was an error while downloading $localFilePath";
}

Answer №1

ftp_get is designed to work with file paths rather than folder paths in both of its arguments.

Therefore, the correct usage would be:

$localFilePath  = 'documents/myfile.docx';
$remoteFilePath = 'public_html/docs/myfile.docx';

ftp_get($connId, $localFilePath, $remoteFilePath, FTP_BINARY);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

In Laravel with PHP, you can conclude the request by delivering a response based on specific conditions

After building a login backend, I realized the importance of checking specific conditions before allowing users to log in. However, I encountered a challenge where I needed to send different responses for each failed attempt. In the method below called in ...

Parsing through a deeply nested JSON array with PHP

Here is my JSON array: [ { "custClass": [ { "code": "50824109d3b1947c9d9390ac5caae0ef", "desc": "e1f96b98047adbc39f8baf8f4aa36f41" }, { "code": "dab6cc0ed3688f96333d91fd979c5f74", ...

Curl malfunction: No response received from server

I am facing issues while attempting a CURL Post. My task involves posting a list of zip codes to an API, and for certain selections, the list can potentially be quite long. The process works flawlessly when I post only a few zip codes. However, when I inc ...

Is there a way to display the directory link using PHP?

I have a Word document saved in my folder, and its name is already in the database. I want to display this document from the folder using PHP. When someone clicks on the link, the entire document should appear on the front end. $sql = "SELECT * FROM user ...

PHP - WebCalendar - Show or Hide Field According to Selected Item in Dropdown List

Working with the WebCalendar app found at to make some personalized adjustments to how extra fields function. I've set up two additional fields: one is a dropdown list of counties, and the other is a text field. Within the dropdown list, there is an ...

How do you link a failing test to a reference when using $this->fail()?

Incorporating my custom assertion into Laravel's base TestCase class is something I'm working on. Here is a snippet of what it looks like: <?php namespace Tests\Mine; use Tests\TestCase; class SomeTest extends TestCase { publi ...

Secure Routes and Views with Laravel Package?

I've been creating a custom package specifically for Laravel 5.2 and I have reached the stage where I am integrating Authentication. I attempted to include an Auth folder in my resources/views directory, along with the necessary Controllers in my pac ...

Empty space under the banner in Wordpress theme Avada

I can't seem to locate the CSS class for a blank space that appears below the header on one of my pages. This space is situated between the header and "SERVICIOS 24 HORAS". Any ideas on how I can remove this mysterious gap? My website is built wit ...

Retrieve data from the child window or obtain the uploaded file name

My issue involves a form that captures multiple entries and inserts them into a database via post data. This functionality works well. Additionally, I have a file upload form that effectively renames and moves files. However, my challenge lies in integrati ...

Print values to screen during the execution of a loop in PHP

Is there a method to display content on the screen while executing a lengthy foreach loop? When I run a loop that consumes a lot of time, the output does not show on the screen until the loop has completed - even when using echo statements within the loop ...

Choose only unique values from two columns

In my database, I have a table called "messages" that looks like this: | receive | transmit | --------------------- | 1 | 5 | | 1 | 6 | | 1 | 3 | | 3 | 1 | | 4 | 1 | | 2 | 3 | | 4 | 6 | | 7 ...

Error encountered while trying to add a record to the MySQL database table

Below is the code snippet I am working with: $username = $connection->real_escape_string($username); $html = $connection->real_escape_string($html); $query = $connection->query("SELECT * from savedarticles WHERE username = '$ ...

What are some recommended strategies for implementing security measures in JAX-WS?

Consider the following situation: I have a set of web services (JAX-WS) that require secure access. Currently, for authentication purposes, I am using an additional SecurityWService that provides authorized users with a userid and sessionid to include in r ...

Establishing the focal point and emphasis within a textarea input field

I am presenting a textarea input through PHP with the following command : print " '<textarea rows='16' cols='30'>$flist'</textarea><BR>"; I want the textarea to receive focus and automatically select the co ...

Utilizing Bootstrap modal to insert data into phpMyAdmin database - a comprehensive guide

I'm attempting to insert data into my localhost database using a Bootstrap modal in conjunction with Laravel 5.2. Here is the PHP function I am using: public function addReport(Request $request) { $postreport = new PostReport(); $postreport- ...

Utilizing PHP and jQuery Ajax in conjunction with infinite scroll functionality to enhance filtering capabilities

I have implemented infinite-ajax-scroll in my PHP Laravel project. This project displays a long list of divs and instead of using pagination, I opted to show all results on the same page by allowing users to scroll down. The filtering functionality works s ...

What is the most effective method for sending a newsletter using PHPMailer?

I am currently working on sending out newsletters using PHPMailer while also safeguarding my customers' privacy. Initially, I configured the receiver settings with mail->addAddress('customerEmail']);. However, I discovered that by sendin ...

Get access to the file upload field using ajax

I'm encountering an issue with accessing the file upload field //HTML <input type='file' name='images' id="images" multiple> ////////////////// $('.bt-add-com').click(function(){ var formdata = new For ...

Is it possible to use an if-else statement for both IP validation and URL validation?

Revise. I'm facing some issues with my code and I'm not sure why. I've added the 'FILTER_FLAG_NO_PRIV_RANGE' flag and also included a check to see if 'localhost' was entered. However, despite these efforts, it doesn&apos ...

Leveraging the power of MySQL and PHP to handle nested JSON data in AngularJs with ng-options

Can someone please guide me on how to generate nested JSON data using MySQL and PHP in Codeigniter? I am looking to structure my data in the specific format shown below. $data = { 'India': { 'Andhra Pradesh': ['Vijay ...