简体   繁体   中英

php ftp_get() not working in Docker container

I am trying to retrieve a file from an ftp in a Docker container using php. The script I have works locally, but the file is not being retrieved from Docker. Here is my Dockerfile

FROM debian:jessie
RUN apt-get update && apt-get install -y php5-cli php5-curl git cron ca-certificates
ADD startup.sh /
CMD ["/startup.sh"]

startup.sh just downloads the actual script to run from source control, and sets up a cron job. The call to the ftp is this:

 $connection = ftp_connect('theftpsite.com');
 $login = ftp_login($connection, 'myusername', 'mypassword');
 ftp_get($connection, 'localfile.xml', 'remotefile.xml', FTP_BINARY);
 ftp_close($connection);

The erros we receive are

ftp_fget(): Switching to Binary mode.

followed by

FTP Pull failed

Is there anything else I need to install in my container to get this to work?

We needed to add

ftp_pasv($connection, TRUE); 

before the ftp_get(). This is the working solution:

$connection = ftp_connect('theftpsite.com');
$login = ftp_login($connection, 'myusername', 'mypassword');
ftp_pasv($connection, TRUE); 
ftp_get($connection, 'localfile.xml', 'remotefile.xml', FTP_BINARY);
ftp_close($connection);

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