ServerForum.org - The Professional IT Community

Full Version: PHP file to transfer a CSV to another server
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi Guys,

I wrote a php file to transfer a CSV regularly to another server. Unfortunately, nothing is transmitted. Does anyone have an idea what is wrong?

PHP Code:
<? 
set_time_limit(999); 

/*** 
nun FTP Upload mit curl 
***/ 
function curlUpload($ftp,$ftpFile) { 
     
    $fp   = fopen($ftpFile, "r");  
    $url  = "ftp://".$ftp['user'].":".$ftp['passwd']."@".  
             $ftp['host'].":21" .$ftp['pfad'].$ftp['file'];  
     
    $handle = curl_init();      
     
    curl_setopt($handle, CURLOPT_URL, $url);   
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);   
    curl_setopt($handle, CURLOPT_UPLOAD, 1);   
    curl_setopt($handle, CURLOPT_INFILE, $fp);   
    curl_setopt($handle, CURLOPT_INFILESIZE, filesize($ftpFile));   
    curl_setopt($handle, CURLOPT_TIMEOUT, 900); 
    curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 900); 


    $result = curl_exec($handle);   

    $info = curl_getinfo ($handle); 

    curl_close($handle);  
     
    return $info;  

}  

$ftp['user'] = '1000732382'; 
$ftp['passwd'] = 'x1h0cJl5'; 
$ftp['host'] = 'ftp.test.at'; 
$ftp['pfad'] = '/Schnittstelle_TEST/'; 
$ftp['file'] = "text.csv"; 
$ftpFile = "text.csv"; 

$info = curlUpload($ftp,$ftpFile); 

print_r($info); 
?>


In response comes:
PHP Code:
Array ( [url] => ftp://test@ftp.test..de:21/text.csv [content_type] => [http_code] => 421 [header_size] => 0 [request_size] => 0 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.065181 [namelookup_time] => 0.004295 [connect_time] => 0.022713 [pretransfer_time] => 0 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => -1 [upload_content_length] => -1 [starttransfer_time] => 0 [redirect_time] => 0 [redirect_url] => [primary_ip] => 0.0.0.0 [certinfo] => Array ( ) [primary_port] => 21 [local_ip] => 0.0.0.0 [local_port] => 52838 )   
Hi,

Error code: 421 says that the server does not handle your request. Possibly is there no FTP service is running?
How would you do it otherwise? Via FileZilla the access to the server works, therefore the FTP-service should be running
Hi, 

How about

$ url = "ftps: //:

instead of

$ url = "ftp: //:

or with another port that listens to SSL instead of 21 or with ftp_ssl_connect please have a look at  http://php.net/manual/en/function.ftp-ssl-connect.php
Perfect! Works fine now...