Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6230237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:42:36+00:00 2026-05-24T09:42:36+00:00

There is a .TXT file with utf8 encoding (if i’m correct) on a external

  • 0

There is a .TXT file with utf8 encoding (if i’m correct) on a external FTP server. I want to download this through a php script to my own ftp server.
So i wrote a script, but when i look at the .txt, i see characters with a character that should be é looks like ën.
How can i do this correct? (also, if i run the same script again i want the old file being replaced with a fresh new file). This is my code:

<?php
// connecting with ftp server
$connection_id = ftp_connect('ftp.example.com'); 
// login with username and password
$login = ftp_login($connection_id, 'username', 'password'); 

// check connection
if ((!$connection_id) || (!$login)) {
   echo 'FTP connection has failed.';
   exit();
} else {
   echo 'Connection succeeded.';
}

$local_file = 'home/file.TXT'; 
$server_file = '/file.TXT';

// open file
$handle = fopen($local_file, 'w+');

// try to download txt file and save it locally
if(ftp_fget($connection_id, $handle, $server_file, FTP_BINARY, 0)) {
     echo 'Succesfully written to '.$local_file;
} else {
    echo 'Not succesfully downloaded!';
}

// close file handler
 fclose($handle);

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

Btw, does anbody know how to make life easier for showing code on stackoverflow by not indenting every single line by pressing on space for four times?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T09:42:37+00:00Added an answer on May 24, 2026 at 9:42 am

    Bynary ftp transfer doesn’t touch the character encoding of the text file. It copies at the bit level. It doesn’t care what kind of data it transfers.

    Have you tried to open both local and server file in your text viewer/editor?
    If they look the same this could mean only two things:
    1. The file is not UTF-8 on the server and this means that the copy will not be either.
    2. Your editor/viewer doesn’t support UTF-8 (or it doesn’t know that the text should be displayed as UTF-8).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In C# you can use verbatim strings like this: @\\server\share\file.txt Is there something similar
Is there a way to get the size of a remote file http://my_url/my_file.txt without
Let's say there is a file called myfile.txt with the following contents: one two
Lets say I have a file called foo.txt encoded in utf8: aoeu qjkx ñpyf
$ cat file.txt one two three $ cat file.txt | sed s/one/1/ 1 two
Given file names like these: /the/path/foo.txt bar.txt I hope to get: foo bar Why
There is a standard two-pass algorithm mentioned in RFC 1942: http://www.ietf.org/rfc/rfc1942.txt however I haven't
I need some help from the shell-script gurus out there. I have a .txt
Say I have three files (template_*.txt): template_x.txt template_y.txt template_z.txt I want to copy them
I am currently testing out using OSGi. I am running this through Eclipse. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.