I'm encountering strange behavior with a simple PHP script that uploads a file to a ftp server.
I've created the following stripped down version of my code which produces the same error:
<?php
error_reporting(E_ALL);
echo phpversion();
$ftpUrl = "mydomain";
$ftpUserName = "myuser";
$ftpPassword = 'mypass';
$fileContents = "test";
file_put_contents('text.txt', $fileContents);
//open ftp connection
$conn_id = ftp_connect($ftpUrl, 1030);
if(!$conn_id)
die('error while connecting to ftp');
$login_result = ftp_login($conn_id, $ftpUserName, $ftpPassword);
if (!$login_result)
die('ftp login failed!');
//switch to passive mode
ftp_pasv($conn_id, true);
//upload file to ftp
try
{
$fileToUpload = fopen('text.txt', 'r');
if($fileToUpload == false)
die('can\'t open file to send!');
$upload = ftp_fput($conn_id, 'testfile.txt', $fileToUpload, FTP_ASCII);
}
catch(Exception $e)
{
fclose($fileToUpload);
ftp_close($conn_id);
die('Error while uploading to ftp');
}
fclose($fileToUpload);
ftp_close($conn_id);
if (!$upload)
die('ftp upload failed');
?>
On the client's ftp server I get the following error when running the script. (the error occurs when trying to upload the file, setting up the connection an logging in works)
Warning: ftp_fput() [function.ftp-fput]: php_connect_nonb() failed: Operation now in progress (115) in {path} on line 38
Warning: ftp_fput() [function.ftp-fput]: Type set to A in {path} on line 38
ftp upload failed
- Uploading the same file with filezilla to this ftp server works fine.
- The file only contains a few lines of text.
- When running this script on a different server, it works fine.
The server uses php version 5.3.28
I've been struggling with this error for hours now and it is driving me crazy. Any clues?
Type set to Ais the response from the FTP server acknowledging the request to transfer the file in ASCII mode. - user3338098