2013-10-09 15:05
采纳率: 0%
浏览 70


I am trying to connect to a remote SFTP server using PHP. My code works fine when I connect to a local SFTP account but it times out for remote host. I have made sure through FTP client that host information is correct and its connecting fine.

I am using phpseclib library and my three line code is below.


$sftp = new Net_SFTP('remote_host_IP');
var_dump($sftp->login('<username>', '<password>'));

It returns false (meaning not connected).

What I have done

  • I have whitelisted script in mod_security just in case its blocking that.
  • I have tried same script on my local computer and it connects successfully to remote SFTP.

Any valuable hint please?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dovhpmnm31216
    dovhpmnm31216 2013-10-18 13:32

    This might help others. You need to make sure TCP_OUT port is open on your remote server to make it work.

    Thanks for the help!

    点赞 评论
  • doutingyou2198
    doutingyou2198 2013-10-09 20:20

    Do define('NET_SSH2_LOGGING', 2) before initializing Net_SFTP and then do $sftp->getLog() after $sftp->login()

    That'll provide enough info with which a diagnostic can be made.

    点赞 评论