PHP-FTP connection

Hey, dear everyone!
I’ve just noticed today that it’s not possible to connect to my SFTP via PHP while using cloudflare.
How can this thing be fixed?
https://fsclan.xyz/logs/moveLog.php -> this is my site’s link, sftp.fsclan.xyz is referring to the original IP for my VPS.
Thanks in advance

Also, i’m 100% sure that everything’s correct, I connect to my SFTP with the same details. Also, it works if I connect to my VPS via WinSCP, so I really don’t know where’s the problem.

That SFTP server is reachable for me.

1 Like

exactly, but not via PHP. and I need to connect to my SFTP server via PHP. I can’t solve a thing without it

Then the problem pretty sure is somewhere at the server the PHP script runs on.
May you have blocked outgoing ports or something like this.
Also we can not see the PHP-Code which is getting executed. Also possible there are some errors/missconfigurations

1 Like
<?php
ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);
// connect and login to FTP server
$ftp_server = "sftp.fsclan.xyz";
$ftp_username = "root";
$ftp_userpass = "censored";
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server / username / password");
$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);

// then do something...

// close connection
ftp_close($ftp_conn);
?>

I don’t think there’s any error in this code. It worked before I used Cloudflare.

You pretty sure are using normal FTP which connects to port 21 (FTP-Port)

SFTP Standardport is 22. Please specify the Port and you should be fine

I would recommend this:

ssh2-sftp

1 Like

Yes exactly, thank you so so much.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.