Solved

Unable to connect to FTP Server ftp_connect fails.

Posted on 2004-09-10
6
436 Views
Last Modified: 2007-12-19
Greets all, I am trying to establish an FTP connection to a server which is through our VPN.  I am able to ping the server and I can access it from the computer I'm running this from but from the below code all I get is :

ERROR! Unable to connect to xx.xx.xx.xxx.  I've checked the IP , username and password and all are OK.  Is there maybe something IM missing? is there a port I will need to open up on my end or theirs that's currently being blocked when using ftp_connect ??

Thank you for your help in advance... The following is the complete code :

if( file_exists( $current_dir."/".$filename.".mirror") )            //Download from Mirror location in file
{
list( $ftp_server_address, $ftp_user_name, $ftp_user_pass) = get_ftp_information( $user_branch );
                  
if(!($ftp = ftp_connect( $ftp_server_address ) ) )
{
     place_header( "ERROR! Unable to connect to $ftp_server_address" );
     die;
}
else
     echo "Connected to $ftp_server_address";
                  
if(!($login_result = ftp_login($ftp, "$ftp_user_name", "$ftp_user_pass") ))
{
     place_header("Unable to login!");
     die;
}
else
     echo "Login successful";
                  
if( (!$ftp) || (!$login_result) )
{
     place_header( "FTP connection has failed!  Attempted to connect to $ftp_server for user $user" );
     die;
}
else
     echo "Connected to $ftp_server, for user $user";

$download = ftp_get($ftp, "$current_dir/$filename", "$current_dir/$filename", FTP_BINARY);
                  
if( !$download )
     echo "Ftp download has failed!";
else
     echo "Downloaded $filename to local as $local_file_name";
                  
ftp_quit( $ftp );
}
0
Comment
Question by:darksinclair
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
6 Comments
 
LVL 48

Expert Comment

by:hernst42
ID: 12031445
Maybe there are spaces in the $ftp_server_address

try if(!($ftp = ftp_connect( trim($ftp_server_address) ) ) )
0
 
LVL 5

Author Comment

by:darksinclair
ID: 12031588
--> Sorry hernst42, I checked that stuff, I think this question is in the wrong spot and it's a problem with the VPN actually.

Thanks for the help,

Cheers,
0
 
LVL 48

Expert Comment

by:hernst42
ID: 12031629
You said that you can connect to that server
> I can access it from the computer I'm running this from but from the below code all I get is...
So can you access the ftp-server from the shell of the computer you tried it or not?

If a normal ftp-client can connect it should also work for PHP. If you can't connect from your machine to the ftp-server make sure port 21 and 20 are open and the ftp-server can connect from port 20 to any port on you machine. Are there any NAT-Gatewyas in that way ??
0
 
LVL 5

Author Comment

by:darksinclair
ID: 12031734
This was a stupid problem... I logged off the server that was running the PHP instead of disconnecting.. so the Contivity VPN client was being closed when i logged off.  :(

0
 

Accepted Solution

by:
ee_ai_construct earned 0 total points
ID: 12064292
Please read entire thread.  Asker solved or content important.
Closed, 250 points refunded.
ee_ai_construct (replacement part #xm34)
Community Support Moderator
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question