How to transfer files from another server, using FTP, in PHP

前端 未结 2 1353
难免孤独
难免孤独 2021-01-14 16:38

I am trying to find a way to transfer files from server-to-server. The source server can be any platform, and we may not even really know anything about it except that it su

2条回答
  •  盖世英雄少女心
    2021-01-14 17:11

    This should be a comment, but its a bit long. Copying a file over FTP using PHP might be as simple as

    file_put_contents($fname
        , file_get_contents('FTP://ftp.example com/path/afile'));
    

    But what do you know about where your PHP code is running? It may not have the capability to

    • resolve DNS names
    • make client connections to other/remote services
    • create a listening data channel (for non-passive data channel)

    And we can't answer these questions for you. Hence your first step is to get a proof of concept up and running using similar code to that above before you start worrying about lots of files, directories and synchronisation.

    Why the requirement to implement this in PHP?

提交回复
热议问题