简体   繁体   English

php ftp_get()在Docker容器中不起作用

[英]php ftp_get() not working in Docker container

I am trying to retrieve a file from an ftp in a Docker container using php. 我正在尝试使用php从Docker容器中的ftp检索文件。 The script I have works locally, but the file is not being retrieved from Docker. 我拥有的脚本在本地工作,但未从Docker检索文件。 Here is my Dockerfile 这是我的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. startup.sh只是从源代码控制中下载要运行的实际脚本,并设置了cron作业。 The call to the ftp is this: ftp的调用是这样的:

 $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(). 在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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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