Connection to secure FTP Server from PHP

后端 未结 5 1047
醉梦人生
醉梦人生 2021-02-02 00:11

This question is in line with this question, I am trying to connect to secure FTP Server and it is not able to connect, wierd part is that I am able to do ssh and connect to the

相关标签:
5条回答
  • 2021-02-02 00:47

    I tried the phpseclib library and it works in Windows and Linux.

    If you are using composer, just add in your require section :

    "phpseclib/phpseclib": "0.3.*@dev"
    

    And then, you can do this : http://phpseclib.sourceforge.net/sftp/examples.html#put

    0 讨论(0)
  • 2021-02-02 00:57

    This page has what you seek (I think)

    http://kevin.vanzonneveld.net/techblog/article/make_ssh_connections_with_php/

    and here are the manual pages

    http://php.net/manual/en/book.ssh2.php

    0 讨论(0)
  • 2021-02-02 01:03
    1. Many cheap webhoster will not give you ssh (hence no ftp via ssh aka sftp) but only ssl-secured ftp aka ftps (see here). You might have that problem. As others suggested, use filezilla or another ftp client to test your credits and chosen security method beforehand.

    2. ftp_ssl_connect() at least under windows will be a long journey, since you have to compile your own php binaries, see here.

    3. As this php contributor rightfully points out, no secure connection is secure, as long as you don't know, who you are talking too, aka „peer certification“ through valid certificates.

    4. phpseclib is probably your best bet. But I haven't figure out, how to ensure, it uses peer verification (guessing, the truth is in openssl.conf ...)

    5. So even at the time of writing, I wonder more than ever, if peer-validated ftps (ftp with ssl/tls authentification) is possible... also see my question here.

    0 讨论(0)
  • 2021-02-02 01:06

    I, too, encountered quite a lot of issues when dealing with encrypted connections.

    First thing is to check the protocol you are looking to use. Secure FTP is most commonly refearing to FTP over SHH but can also mean SCP, SFTP or FTPS.

    One way to figure out is to check connecting using a client like filezilla.

    If the protocol is handled via a PHP module, the best approach is indeed, to use it. In this case, you need to make sure that, in addition to the protocol-related one, the OPENSSL module is installed for php.

    There are some cases where the module support still won't work. In this case, using the libcurl module is one option. This is the case for instance when you need to use a client certificate.

    Unfortunately, here again, you may encounter some problems due to the partial support of libcurl in the php module. One scenario I experimented is when the server certificate is judged invalid by the module.

    The last solution I usually use is to run the curl binary from an exec statement, for the later case using the "-k" switch.

    0 讨论(0)
  • 2021-02-02 01:12

    As for ´ftp via ssh´ alias ´sftp´: No direct advice, but note, that many cheap 'non-dedicated server' webhosts do not support it (which is bad). Company firewalls might block the relevant ports.

    As for 'ftp using ssl/tls' alias 'ftps': Your answer is here. Don't waste time on ftp_ssl_connect() :-)

    (Yes, it's poorly documented on the php site, to say the least)

    0 讨论(0)
提交回复
热议问题