简体   繁体   English

通过PHP连接到FTPS

[英]Connecting to FTPS over PHP

I am currently working on a project that involves connecting to the clients FTPS server and downloading a file that they are updating automatically with the data we require. 我目前正在从事一个项目,该项目涉及连接到客户端FTPS服务器并下载一个文件,这些文件将使用我们需要的数据自动更新。 I am wanting to access this server via PHP so I can automate it. 我想通过PHP访问此服务器,以便可以对其进行自动化。

The issue that I have is that FTP_SSL_CONNECT will NOT work due to the client using Implicit TLS security on the server. 我遇到的问题是由于客户端在服务器上使用了隐式TLS安全性,FTP_SSL_CONNECT将无法正常工作。

Does anyone have any experience of getting this connection working? 有没有人有使该连接正常工作的经验?

Thanks, T 谢谢,T

$username = 'username here';
$password = 'password here';
$get_file = "file to get here";
//set ftps url
$url = "ftps urls here";
$local_prefix = 'local folder prefix here';
$location = "ftps://" . $username . ":" . $password . "@" . $url;
$port = "any port number here";
//********************************************************************//
//initialize cURL and begin
print("Initializing cURl and saving file from scure ftp.");
$curl = curl_init();
//create or open a file for writing
$file = fopen("$local_prefix$get_file", "w");
//set cURL options *note* these must occur in order for implicit ftp to work correctly
curl_setopt($curl, CURLOPT_URL, "$location$get_file");
curl_setopt($curl, CURLOPT_PORT, "$port");
curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
curl_setopt($curl, CURLOPT_FILE, $file);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl, CURLOPT_FTP_SSL, CURLFTPSSL_TRY);
curl_exec($curl) or die("did not save file");
curl_close ($curl);
fclose($file);

You need to add these option to curl call 您需要添加这些选项来卷曲通话

CURLOPT_FTP_SSL        => CURLFTPSSL_ALL, // require SSL For both control and data      connections
CURLOPT_FTPSSLAUTH     => CURLFTPAUTH_DEFAULT, // let cURL choose the FTP authentication method (either SSL or TLS)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM