Jump to content

Using ftp_ssl_connect() for SFTP


stevesimo

Recommended Posts

Hi, I have been asked to code an application which for its last job needs to transfer a data textfile using SFTP.  I have been given an IP address and a port to connect to but cant get it to work.  Before posting here I have had a good luck on the internet and was struggling to find any complete examples.  I found the example below but cant get this to work. 

 

Here is my code:

 

  
$ftphost   =   '123.123.123.123';
  $ftpuser   =   'username';
  $ftppwd    =   'password';
  $ftpport   =   10022;
  $timelimit = 30;

  //UTF8 Encode Data
  $data = utf8_encode($data);
  
  // set up ssl connection
  $ftpconn = ftp_ssl_connect($ftphost, $ftpport, $timelimit) or die("Could not connect to FTP server...");
  echo 'Connected to FTP server...<br>';
  
  // login with username and password
  $login_result = ftp_login($ftpconn, $ftpuser, $ftppwd) or die("Could not login to FTP server...<br>"); 
  
  echo ftp_pwd($ftpconn);
  
  
  ftp_close($ftpconn); // close the ssl connection

 

This code doesnt even try to tranfer any files, just tries to connect to server and login but I cannot get it to work.

 

Can anyone point me in the right direction.

 

Many thanks

 

Steve :)

 

 

Link to comment
Share on other sites

From the user docs

 

http://php.net/ftp_ssl_connect

 

Just remember: SSL FTP != SFTP

Differences: an SSL FTP connects on port 990, and you need an ftp server which will support this (seems like none in the SuSE linux distribution do). Even if you get this function to work, and it connects ok to a normal FTP server on port 21, data WILL NOT BE ENCRYPTED. If you don't believe me, go sniff it yourself!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.