Tenho um aplicativo desenvolvido em PHP, CSS, HTML tudo misturado, rsrsrs, este aplicativo funcionou muito bem até meados de julho/2023. Eu estava usando para upload dos pedidos de vendas feito no tablet o comando: ftp_put($ftp, $ftp_arquivo, $local_arquivo, FTP_ASCII) e para download dos arquivos de produtos e clientes o ftp_get($conn_id,$local_file, $remote_file, FTP_ASCII).
1ª pergunta: Por que o ftp_get e ftp_put parou de funcionar?
Obs: Para ENVIO LOCAL, na mesma rede continua funcionando os dois comandos, mas estando usando outra rede lan não funciona. Aplicativo até conecta mas não consegue transferir os arquivos, nem para Download e Upload.
Para receber o arquivos necessários consegui resolver da seguinte forma:
Code: Select all
$curl = curl_init($ftp_server.$ftp_porta);
$fo = fopen("$local_file", 'w');
curl_setopt($curl, CURLOPT_URL, "ftp://$ftp_server:$ftp_porta/$remote_file"); #input
curl_setopt($curl, CURLOPT_TRANSFERTEXT, TRUE);
curl_setopt($curl, CURLOPT_FILE, $fo); #output
curl_setopt($curl, CURLOPT_USERPWD, "$ftp_user_name:$ftp_user_pass");
curl_setopt($curl, CURLOPT_FRESH_CONNECT, true);
if(file_exists($localFile)) {
curl_setopt($curl, CURLOPT_RESUME_FROM, filesize($local_File));
}
curl_exec($curl);
fclose($fo);
curl_close($curl);
Code: Select all
$ftp = ftp_connect($servidor,$porta); // Retorno: true ou false
ftp_raw($ftp, "AUTH TLS");
ftp_raw($ftp, "AUTH SSL");
// Faz o login no servidor FTP
$login = ftp_login($ftp, $usuario, $senha); // Retorno: true ou false
//*****************************************************************//
ftp_raw($ftp, "CWD /backup");
ftp_raw($ftp, "TYPE A");
// Envia o arquivo pelo FTP em modo ASCII
$connect = ftp_raw($ftp, "PASV");
// parse the response and build the IP and port from the values
if (count($connect) > 0 && preg_match("/.*\((\d+),(\d+),(\d+),(\d+),(\d+),(\d+)\)/", $connect[0], $m)) {
$address="{$m[1]}.{$m[2]}.{$m[3]}.{$m[4]}";
$port=$m[5] * 256 + $m[6];
print_r(ftp_raw($ftp, "STOR $ftp_arquivo"));
$sock = socket_create(AF_INET, SOCK_STREAM, 0);
if ($sock) {
socket_connect($sock, $address, $port);
socket_write($sock, file_get_contents($ftp_arquivo));
socket_close($sock);
}
}
ftp_raw($ftp,'QUIT');
Code: Select all
(000036)11/08/2023 16:38:50 - mymobile (179.54.xxx.xxx)> PASV
(000036)11/08/2023 16:38:50 - mymobile (179.54.xxx.xxx)> 227 Entering Passive Mode (xxx,xxx,xxx,xxx,19,171)
(000036)11/08/2023 16:38:50 - mymobile (179.54.xxx.xxx)> STOR pedidos1013110823-10.xml
(000036)11/08/2023 16:39:00 - mymobile (179.54.xxx.xxx)> 425 Can't open data connection.
O interessante é que, fazendo a transferência pelo FileZilla Client não dá erro o arquivo é transferido normalmente, conforme podemos ver no log abaixo.
Code: Select all
(000035)11/08/2023 16:37:36 - mymobile (179.54.xxx.xxx)> 200 Type set to A
(000035)11/08/2023 16:37:36 - mymobile (179.54.xxx.xxx)> PASV
(000035)11/08/2023 16:37:36 - mymobile (179.54.xxx.xxx)> 227 Entering Passive Mode (xxx,xxx,xxx,xxx,19,169)
(000035)11/08/2023 16:37:36 - mymobile (179.54.xxx.xxx)> STOR pedidos1013110823-10.xml
(000035)11/08/2023 16:37:36 - mymobile (179.54.xxx.xxx)> 150 Connection accepted
(000035)11/08/2023 16:37:36 - mymobile (179.54.xxx.xxx)> 226 Transfer OK
2ª pergunta: O que estou fazendo de errado? Existe outra solução?
Sobre o erro 425 eu já liberei as portas no modem e no fileZilla
Porta: 2121 no modem e no fileZilla
Porta passiva: 50000-50100 no modem e Filezilla