简体   繁体   中英

Unable to access FTP server with PHP, but works fine from command line

I'm trying to access FTP with following code (PHP 5.4)

// connect and login FTP
$conn = ftp_connect($host);
ftp_pasv($conn, true);
$login = ftp_login($conn, $user, $password);

// skip some code ...

// upload file
ftp_put($conn, $remote, $local, FTP_BINARY);

With passive mode off,I can login without problem, but got an error when upload file :

ftp_put(): Security server forbids PORT redirection.

With passive mode on, I cannot even login

ftp_login(): Check Point FireWall-1 Secure FTP server running on xxxxx

I can use ftp unix command to access FTP server with the same user and on the same machine without any problem, so I'm really confused.

Can anyone give me some direction how to deal this issue ?

Thanks

I found this stupid error after I post this question:

You need to set passive mode AFTER you logged in !

$conn = ftp_connect($host);
$login = ftp_login($conn, $user, $password);
ftp_pasv($conn, true);

That's why I cannot connect it in passive mode :(

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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