首页 > 解决方案 > Can't Upload folder to FTP Server : ftp_put(): SSL_shutdown failed

问题描述

I'm trying to upload all folder that are located in a specific folder ("Sending") to a FTP Server with that PHP Code :

$conn_id = ftp_ssl_connect($ftp_server, 11876);

$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_password);
if ((!$conn_id) || (!$login_result)) {
    echo "FTP Connection failed to server $ftp_server for user $ftp_user_name";
    exit;
} else {
    echo "Connected to Server $ftp_server, for user $ftp_user_name \r\n";
}

$remoteDir = "/Disque dur/Téléchargements/";
$dir = 'Sending';
$files = array_diff(scandir($dir), array('..', '.'));
$directories = array();
foreach ($files as $file) {
    if (is_dir($dir . '/' . $file))
        $directories[] = $file;
}
ftp_pasv($conn_id, true);

foreach ($directories as $directory) {
    if (ftp_chdir($conn_id, $remoteDir . $directory)) {
        echo "Current directory is now: " . ftp_pwd($conn_id) . "\n";
    } else {
        echo "Couldn't change directory\n";
        ftp_mkdir($conn_id, $remoteDir . $directory);
        ftp_chdir($conn_id, $remoteDir . $directory);
    }
    foreach (glob($dir . "/" . $directory . "/*.*") as $filename){
        ftp_put($conn_id, basename($filename), $filename, FTP_BINARY);
    }

}

ftp_close($conn_id);

But i have an error at this line :

ftp_put($conn_id, basename($filename), $filename, FTP_BINARY);

And the logs are

Connected to Server MYSERVER, for user USER
Current directory is now: /Disque dur/Téléchargements/DIRECTORY/
Warning: ftp_put(): SSL_shutdown failed
Warning: ftp_put(): Data channel closed.

There is something specific to my FTP Server : the connection port : 11876 is not the same as the Passive Transfer Port : 9317.

When I try to connect directly to the transfer port, the connection returns false.

Edit : I just figured out : The file is uploaded anyway so is there a way to remove this Warning and why does it appear?

But I can send folders trough Filezilla on the port 118976. What am I doing wrong? Can someone help me?

Logs from FileZilla :

2019-06-26 18:12:30 13664 1 Status: Resolving address of ADRESS
2019-06-26 18:12:30 13664 1 Status: Connecting to IP:11876...
2019-06-26 18:12:30 13664 1 Status: Connection established, waiting for welcome message...
2019-06-26 18:12:30 13664 1 Response: 220 Welcome to Freebox FTP Server.
2019-06-26 18:12:30 13664 1 Command: AUTH TLS
2019-06-26 18:12:30 13664 1 Response: 234 Proceed with negotiation.
2019-06-26 18:12:30 13664 1 Status: Initializing TLS...
2019-06-26 18:12:30 13664 1 Status: Verifying certificate...
2019-06-26 18:12:30 13664 1 Status: TLS connection established.
2019-06-26 18:12:30 13664 1 Command: USER USERNAME
2019-06-26 18:12:30 13664 1 Response: 331 User name okay, need password.
2019-06-26 18:12:30 13664 1 Command: PASS ********************
2019-06-26 18:12:30 13664 1 Response: 230 User logged in, proceed.
2019-06-26 18:12:30 13664 1 Command: SYST
2019-06-26 18:12:30 13664 1 Response: 215 UNIX Type: L8
2019-06-26 18:12:30 13664 1 Command: FEAT
2019-06-26 18:12:30 13664 1 Response: 211-Extensions supported:
2019-06-26 18:12:30 13664 1 Response:  UTF8
2019-06-26 18:12:30 13664 1 Response:  EPRT
2019-06-26 18:12:30 13664 1 Response:  EPSV
2019-06-26 18:12:30 13664 1 Response:  REST STREAM
2019-06-26 18:12:30 13664 1 Response:  SIZE
2019-06-26 18:12:30 13664 1 Response:  CLNT
2019-06-26 18:12:30 13664 1 Response:  AUTH TLS
2019-06-26 18:12:30 13664 1 Response:  PBSZ
2019-06-26 18:12:30 13664 1 Response:  PROT
2019-06-26 18:12:30 13664 1 Response: 211 End
2019-06-26 18:12:30 13664 1 Command: CLNT FileZilla
2019-06-26 18:12:30 13664 1 Response: 200 Command Okay.
2019-06-26 18:12:30 13664 1 Command: OPTS UTF8 ON
2019-06-26 18:12:30 13664 1 Response: 200 Command Okay.
2019-06-26 18:12:30 13664 1 Command: PBSZ 0
2019-06-26 18:12:30 13664 1 Response: 200 Command Okay.
2019-06-26 18:12:30 13664 1 Command: PROT P
2019-06-26 18:12:30 13664 1 Response: 200 Command Okay.
2019-06-26 18:12:30 13664 1 Status: Logged in
2019-06-26 18:12:30 13664 1 Status: Retrieving directory listing...
2019-06-26 18:12:30 13664 1 Command: PWD
2019-06-26 18:12:30 13664 1 Response: 257 "/"
2019-06-26 18:12:30 13664 1 Command: TYPE I
2019-06-26 18:12:30 13664 1 Response: 200 Command Okay.
2019-06-26 18:12:30 13664 1 Command: PASV
2019-06-26 18:12:30 13664 1 Response: 227 PASV OK (IP)
2019-06-26 18:12:30 13664 1 Command: LIST
2019-06-26 18:12:30 13664 1 Response: 150 File Status OK.
2019-06-26 18:12:30 13664 1 Response: 226 Closing data connection.
2019-06-26 18:12:30 13664 1 Status: Directory listing of "/" successful

标签: phpsslftpport

解决方案


推荐阅读