Hello everyone.

I am having some trouble logging into a secure ftp server where I am downloading a zip file onto my server. When use this script to login to one of my servers, it works just fine. When I change the data to login to a site I pull data from, I get a timeout error that reads "the server unexpectedly dropped the connection". Here is the script I am using:

<?php
//grab data
$ftp_server = "ftpserver.com";
$ftp_user_name = "username";
$ftp_user_pass = "password"; 
$local_file = 'local_file';
$server_file = 'server_file';

// set up basic connection
$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// try to download $server_file and save to $local_file
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) {
    echo "Successfully written to $local_file\n$server_file";
} else {
    echo "There was a problem\n";
}

// close the connection
ftp_close($conn_id);

?>

If anybody can help me with any input it would greatly be appreciated. I am having a hard time figuring out why it works on one server but not another.

Thanks in advance.

    Are you behind a firewall at your place of work? I had the same problem. I could login to internal FTP servers but nothing external unless it was "white listed"

      Thanks for your response.

      No, both servers are not local and not housed at my location. Its a weird problem that I hope has a simple fix, but I cannot seem to figure it out. What I have been doing is using an ftp client to move the file off the data server to my servers, then I run my scripts to extract and file the data into another server. I hate that I have to use an additional server to act like a middle-man to use my scripts. There has to be a better way to do this.

      What I would like to do is get the scripts to work on the correct server so I can set up a cron job to run the script everyday and take this task off my list.

      Thanks again for your response.

        Write a Reply...