我一直試圖用明確的TLS/SSL服務器推送到遠程FTP,並且連接保持超時。它是連接的,但我不知道它在哪裏停止,但我認爲這對於FTP/TLS/SSL控制通道是有用的。任何幫助將不勝感激。帶卷積TLS/SSL的PHP curl FTP
通過FileZilla我可以連接沒有問題,但不通過捲曲。我可能錯過了一些東西,並希望這裏有人會知道使用curl重新創建會話的最佳方式。以下是FileZilla的調試輸出以及我在PHP/curl中處理的示例代碼。這裏是PHP代碼,下面是一個成功的FileZilla會話的副本。
這裏是版本,但我試過它在不同的系統上有相同的結果。
Curl: v7.43.0
└─(08:04:00 on master ✹)──> php -v ──(Thu,Sep10)─┘
PHP 5.5.27 (cli) (built: Jul 14 2015 17:04:01)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
with Xdebug v2.3.3, Copyright (c) 2002-2015, by Derick Rethans
這裏是實際的代碼。
<?php
$server_data = array(
'transfer_id' => 123456789,
'post_url' => "ftps://ftps.widgetsltd.com",
'port' => 21,
'username' => 'widgetsftp',
'password' => 'password',
);
$filename = sprintf("%s-%s-%s.csv",
$server_data['transfer_id'],
microtime(TRUE),
rand(1000, 9999));
$temp_filename = sprintf("/tmp/%s", $filename);
$ftp_data = "This is a test";
$fp = fopen($temp_filename, 'w');
fprintf($fp, "%s", $ftp_data);
fclose($fp);
$fp = fopen($temp_filename, 'r');
$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_URL, sprintf("%s/%s", $server_data['post_url'], $filename));
curl_setopt($ch, CURLOPT_PORT, 21);
curl_setopt($ch, CURLOPT_USERPWD, sprintf("%s:%s", $server_data['username'], $server_data['password']));
curl_setopt($ch, CURLOPT_UPLOAD, TRUE);
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($temp_filename));
curl_setopt($ch, CURLOPT_USE_SSL, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_0);
curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, 'AES-128-CBC');
curl_setopt($ch, CURLOPT_FTP_SSL, CURLOPT_FTPSSLAUTH);
curl_setopt($ch, CURLOPT_FTPSSLAUTH, CURLFTPAUTH_TLS);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
print_r(array('curl_exec' => curl_exec($ch)));
print_r(array(
'curl_errno' => curl_errno($ch),
'curl_error' => curl_error($ch),
));
這是FileZilla會話。
Status: Resolving address of ftps.widgetsltd.com
Status: Connecting to 123.123.123.123:21...
Status: Connection established, waiting for welcome message...
Trace: CFtpControlSocket::OnReceive()
Response: 220-Microsoft FTP Service
Response: 220 Widgets, LTD FTP server
Trace: CFtpControlSocket::SendNextCommand()
Command: AUTH TLS
Trace: CFtpControlSocket::OnReceive()
Response: 234 AUTH command ok. Expecting TLS Negotiation.
Status: Initializing TLS...
Trace: CTlsSocket::Handshake()
Trace: CTlsSocket::ContinueHandshake()
Trace: CTlsSocket::OnSend()
Trace: CTlsSocket::OnRead()
Trace: CTlsSocket::ContinueHandshake()
Trace: CTlsSocket::OnRead()
Trace: CTlsSocket::ContinueHandshake()
Trace: TLS Handshake successful
Trace: Protocol: TLS1.0, Key exchange: RSA, Cipher: AES-128-CBC, MAC: SHA1
Status: Verifying certificate...
Status: TLS connection established.
Trace: CFtpControlSocket::SendNextCommand()
Command: USER s-rokfri
Trace: CTlsSocket::OnRead()
Trace: CFtpControlSocket::OnReceive()
Response: 331 Password required for s-rokfri.
Trace: CFtpControlSocket::SendNextCommand()
Command: PASS ********
Trace: CTlsSocket::OnRead()
Trace: CFtpControlSocket::OnReceive()
Response: 230-This service and information contained therein belong to Widgets, LTD.
Response: 230 User logged in.
Trace: CFtpControlSocket::SendNextCommand()
Command: OPTS UTF8 ON
Trace: CTlsSocket::OnRead()
Trace: CFtpControlSocket::OnReceive()
Response: 200 OPTS UTF8 command successful - UTF8 encoding now ON.
Trace: CFtpControlSocket::SendNextCommand()
Command: PBSZ 0
Trace: CTlsSocket::OnRead()
Trace: CFtpControlSocket::OnReceive()
Response: 200 PBSZ command successful.
Trace: CFtpControlSocket::SendNextCommand()
Command: PROT P
Trace: CTlsSocket::OnRead()
Trace: CFtpControlSocket::OnReceive()
Response: 200 PROT command successful.
Status: Connected
Trace: CFtpControlSocket::ResetOperation(0)
Trace: CControlSocket::ResetOperation(0)
Trace: CFileZillaEnginePrivate::ResetOperation(0)
Trace: Measured latency of 141 ms
Status: Retrieving directory listing...
Trace: CFtpControlSocket::SendNextCommand()
Trace: CFtpControlSocket::ChangeDirSend()
Command: PWD
Trace: CTlsSocket::OnRead()
Trace: CFtpControlSocket::OnReceive()
Response: 257 "/" is current directory.
Trace: CFtpControlSocket::ResetOperation(0)
Trace: CControlSocket::ResetOperation(0)
Trace: CFtpControlSocket::ParseSubcommandResult(0)
Trace: CFtpControlSocket::ListSubcommandResult()
Trace: state = 1
Trace: CFtpControlSocket::ResetOperation(0)
Trace: CControlSocket::ResetOperation(0)
Status: Directory listing of "/" successful
Trace: CFileZillaEnginePrivate::ResetOperation(0)
這裏是捲曲輸出。
* Trying 123.123.123.123...
* Connected to ftps.widgetsltd.com (123.123.123.123) port 21 (#0)
* SSL connection timeout
* Closing connection 0
Array
(
[curl_exec] =>
)
Array
(
[curl_errno] => 28
[curl_error] => SSL connection timeout
)
確實[這太問題(HTTP://計算器。com/questions/9906555/ftp-upload-file-to-distant-server-with-curl-and-php-uploads-a-blank-file)help? –
不是真的,讓這更復雜的事情是顯式ssl。但是,謝謝。 – jbrahy
想到我會試試:)希望我能有更多的幫助... –