I'm trying to read a csv file on a distant server using the ftp_fget
and fgetcsv
functions. I already practice this multiple times when reading files on distant servers and until now it works fine.
I can't figure out why ftp_fget is returning this error: bind() failed: Permission denied (13)
.
Furthermore, I can't find any real explanations about this error message too.
My client who gave me distant server access said it's a Windows Server.
$distant_folder = "/myfolder/";
$filename = "myfile.csv";
$ftpstream = ftp_connect($ftp_server);
$login = ftp_login($ftpstream, $ftp_user, $ftp_pass);
if($login){
$tmp_handle = fopen('php://temp', 'r+');
if (ftp_fget($ftpstream, $tmp_handle, $distant_folder.$filename, FTP_ASCII)){
// do stuff with fgetcsv()...
}
}
Please notice values of the ftp server variables are hidden for confidential reasons.
EDIT : I found a solution!
I used ftp_pasv($ftpstream, true);
between ftplogin()
and ftp_fget()
functions.
You have to switch the connection to passive mode, so your FTP client ask a port to connect to the FTP server. Put it before ftp_put(), ftp_get(), ftp_nlist(), etc. for example:
ftp_pasv($connId, true);
$list = ftp_nlist($connId, ".");