/    Sign up×
Community /Pin to ProfileBookmark

Failed to connect using ftp_connect

Hi, I’m new to FTP using PHP. I need to ftp a remote server to retrieve and save a file to my local C: drive. The very first step I did is:

$ftp_server = “202.xxx.xxx.xxx”; //xxx will be replaced with remote server IP address
$conn_id = ftp_connect($ftp_server);
$ftp_user_name = “testuser”;
$ftp_user_pass = “testuser”;

$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// check connection
if ((!$conn_id) || (!$login_result))
{
echo “FTP connection failed”;
exit;
}
else
echo “Connected!”;

I always failed to connect to the server. Hence, I tried using my own computer IP address and username & password, but the connection failed too. ? What’s wrong with my code? ?
Please enlighten me.
Thank you.

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@bokehSep 20.2006 — [I]In order to use FTP functions with your PHP configuration, you should add the --enable-ftp option when installing PHP 4 or greater[/I]
Copy linkTweet thisAlerts:
@chazzySep 20.2006 — also, you need to ensure that an actual FTP server is running on the system you are connecting to.
Copy linkTweet thisAlerts:
@YukimiauthorSep 21.2006 — Hi Bokeh and Chazzy, thank you for your reply. FYI, my Apache server has --enable-ftp option and the actual FTP server is running. I tried to connect to the remote server using a FTP software and it works well. In other words, there's problem with my php script. I really have no idea what goes wrong. Please help.

Thank you.
Copy linkTweet thisAlerts:
@chazzySep 21.2006 — do you need to go through SSL for this connection maybe?
Copy linkTweet thisAlerts:
@bokehSep 21.2006 — Have you got display errors enabled and set to E_ALL?
×

Success!

Help @Yukimi spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...