0

Possible Duplicate:
Warning: mysql_fetch_row() expects parameter 1 to be resource

I have asked the question before but in a different manner. I am trying taking form data, compiling into a temporary CSV file and trying to send over to a client via FTP over SSL (this is the only route I am interested in hearing solutions for unless there is a workaround to doing this, I cannot make changes). I have tried the following:

  1. ftp_connect - nothing happens, the page just times out
  2. ftp_ssl_connect - nothing happens, the page just times out
  3. curl library - same thing, given URL it also gives error.

I am given the following information:

  • FTPS Server IP Address
  • TCP Port (1234)
  • Username
  • Password
  • Data Directory to dump file
  • FTP Mode: Passive

very, very basic code (which I believe should initiate a connection at minimum): Code:

<?php
$ftp_server = "00.000.00.000";  //masked for security
$ftp_port = "1234"; // masked but not 990
$ftp_user_name = "username";
$ftp_user_pass = "password";


// set up basic ssl connection
$conn_id = ftp_ssl_connect($ftp_server, $ftp_port, "20");

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
ftp_pasv($conn_id, true);

echo ftp_pwd($conn_id); // /
echo "hello";

// close the ssl connection
ftp_close($conn_id);

?>

When I run this over a SmartFTP client, everything works just fine. I just can't get it to work using PHP (which is a necessity). Has anybody had success doing this in the past? I would be very interested to hear your approach.

EDIT I added the ftp_pasv() command after ftp_login as mentioned below but am still unable to connect. I am given the following errors:

Warning: ftp_login() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\test.php on line 12

Warning: ftp_pasv() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\test.php on line 14

Warning: ftp_pwd() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\test.php on line 16

Warning: ftp_close() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\test.php on line 20

Community
  • 1
  • 1
JM4
  • 6,740
  • 18
  • 77
  • 125
  • Are you using a valid SSL cert or a self-signed SSL cert? Curl will try to validate the SSL cert against a cert authority. SmartFTP you can click past the SSL cert validation. PHP's `ftp_ssl_connect()` might also try to validate the SSL cert. – Geek Num 88 May 26 '10 at 00:05
  • @Geek Num 88 - I am using a valid ssl Cert obtained through Go Daddy – JM4 May 26 '10 at 00:07
  • When you use smartFTP, does ssl work on port 20? typically that's port 21. – Dan Heberden May 26 '10 at 00:16
  • @JM4 a few more ideas, `ftp_pasv()` needs to be called after `ftp_login()`. Have you checked your error logs? – Geek Num 88 May 26 '10 at 00:20
  • @JM4 also just to be sure the *remote* server needs a valid SSL cert not your server – Geek Num 88 May 26 '10 at 00:21
  • @Dan - the port number is irrelevant but fyi we are connecting to port 4433 in this case. @Geek Num 88 - I'll have to ask the client on the SSL cert on their end. I'll try using the ftp_pasv() command as well – JM4 May 26 '10 at 14:36
  • Irrelevant? Do you mean you're not posting the 'real' one and have already take that into consideration? Otherwise it is definitely relevant: if i try to connect to my FTP server on port 21 when it's running on 2222, it ain't gonna work :p – Dan Heberden May 26 '10 at 14:45
  • @Dan - I do not post the real port number in the example code. The real port is 4433 as I said before. Connecting using PHP fails out. Connecting using SmartFTP works with the settings described above. – JM4 May 26 '10 at 14:50
  • Ok ok - just makin' sure. I was afraid you meant "it's port 4433, but i'm putting 20 in my code because it doesn't matter", heh. It's the 'you sure its plugged in?' part of me... – Dan Heberden May 26 '10 at 14:54

2 Answers2

0

Is FTP enabled in your PHP installation? Use phpinfo(); to echo your installation info. There should be a section for ftp, with "FTP Support - enabled" in a table.

Dan Heberden
  • 10,990
  • 3
  • 33
  • 29
0

First, you need to find out which secure FTP you are using,

  1. SFTP : SSH FTP
  2. FTPS : FTP over SSL

For FTPS to work, the openssl module must be statically linked (not installed as a dynamic extension).

SFTP requires PECL ssh2 extension.

ZZ Coder
  • 74,484
  • 29
  • 137
  • 169
  • @ZZ Coder - As the question states, I'm looking for 2 - FTPS - FTP over SSL. I'm not sure what 'statically linked' means in this terms of this question. – JM4 May 26 '10 at 14:33
  • Check your php.ini, if you see something like "extension=openssl.so", it's dynamic. FTPS doesn't work with dynamic extensions. But this is probably not your problem. We get errors right away, not hanging. – ZZ Coder May 26 '10 at 14:54
  • @ZZ Coder - this extension doesn't exit on my system so I dont think it's the cause of the error – JM4 May 26 '10 at 15:11
  • Check a similar line for FTP also. Both needs to be static. Another suggestion is to try CURL with a syntax like "ftps://host:port/path/file". – ZZ Coder May 26 '10 at 15:32