I am attempting to retrieve a file in a certain directory on Server A from a browser session on Server B using PHP's ftp_connect() function.
Server B's IP address has been whitelisted on Server A.
When I run the script I get "Could not connect to 123.123.123.123".
Here is my script:
<?php
$ftp_host = "123.123.123.123"; // real IP Address masked
$ftp_port = "22";
$ftp_conn = ftp_connect($ftp_host,$ftp_port) or die("Could not connect to $ftp_host");
echo 'connection success'; exit;
Why won't this work? Is there a better way to retrieve the file using PHP?
Here is the results of the "duplicate" question and answers -- they do not work:
- $connection = ssh2_connect('123.123.123.123', 22); Results in: Fatal error: Call to undefined function ssh2_connect() in ...
- file_get_contents('ssh2.sftp://user:pass@example.com:22/path/to/filename'); Results in Warning: file_get_contents(): Unable to find the wrapper "ssh2.sftp" - did you forget to enable it when you configured PHP?
I am wondering if anyone has had any success making an FTP connection to a server using PHP when you have a proven & valid username, password, host and port.
If you have, can you share how you did it?
10/3/2018 recap and explanation of my objective Here is what I need to do:
- There is a file on a host server that is being updated and served to me each and every day of the week by a host datacenter.
- The host data center has whitelisted my server's IP address.
- I have successfully logged into the host datacenter server via Sublime Text 3 with settings type=sftp, host=(host datacenter's server IP address), port=22, username=(username they gave me), password=(password they gave me), remote_path=(path they gave me.)
- I do not want to manually login to the server and physically extract the data file for use on my site -- I want to programmatically do it via PHP (or even bash as someone suggested).
I am open to any assistance or ideas where this has been done successfully.
Problem Solved!
In order to use the ssh2_connect() function, you need to install and activate the PHP SSH2 extension. From all of my digging, googling and research nowhere was it stated that the extension is not active with PHP (out-of-the-box) nor did anyone mention it needed to be installed and activated. But now we know :) I hope this helps you out!