l0gin
l0gin

Reputation: 1

The fopen function on a remote FTP server

I need to save form data to a remote ftp server.

If I have a local path set everything works.

$filename = "/home/fvaeytm/test/uploads/user_dirs/$user_login".date("Ymdhis").".txt";

When I try to change the save path of the file like this:

$filename = "ftp://pi:[email protected]/home/pi/test/" . $user_login . date("Ymdhis") . ".txt";

...A file is created on the remote ftp server but has no content.

In the initial stage (for about 30 seconds), the file on the server cannot be opened either.

$filename = "/home/fvaeytm/test/uploads/user_dirs/$user_login".date("Ymdhis").".txt";

$myfile = fopen($filename, "w");

fwrite($myfile, $Name."\n");
fwrite($myfile, $Number."\n");
fclose($myfile);

echo "<div id='success_page'>";
echo "<p>OK</p>";
echo "</div>";
}

I don't know where the problem lies. I tried changing file permissions but no change. Only an empty file is created with the correct name but no content.

I tried on two different FTP servers and the same problem on both.

"allow_url_fopen" in php is set to On


Update: I tried saving on a third server, this time with OVH, and it turns out that everything works fine here.

When I try on my ftp servers that I have at home the file is created but without content.

One FTP server set up on OpenWrt, the other on Debian (Raspberry) - the same problem on both.

I will just add that the domain that is redirected to home servers is parked on Cloudflare but ssl is turned off. Connecting to the client via an external IP, I can easily create and save files on my home FTP server, so I don't know why there is a problem with the script.

Upvotes: 0

Views: 93

Answers (1)

l0gin
l0gin

Reputation: 1

Solution: In addition to the standard port 21 for FTP, I had to open a range of ports: 40000-45000 on the main router.

vsftpd.conf

pasv_min_port=40000
pasv_max_port=45000

Upvotes: 0

Related Questions