FTP unable to connect with fsockopen

FTP unable to connect with fsockopen

am 02.11.2007 16:28:18 von MikeofPet

I am trying to implement FTP in a PHP script but am unable to make the
connection to the remote server. The connection step times out at the
fsockopen function. I am not sure if it is relevant but PHP is
configured with "allow_url_fopen" ON. I am able to do an FTP connect
using an FTP client and using the same host/username/password
parameters.

Any ideas would be appreciated.

Thanks

Re: FTP unable to connect with fsockopen

am 02.11.2007 17:45:40 von colin.mckinnon

On 2 Nov, 15:28, MikeofPet wrote:
> I am trying to implement FTP in a PHP script but am unable to make the
> connection to the remote server. The connection step times out at the
> fsockopen function. I am not sure if it is relevant but PHP is
> configured with "allow_url_fopen" ON. I am able to do an FTP connect
> using an FTP client and using the same host/username/password
> parameters.
>
> Any ideas would be appreciated.
>
> Thanks

It's difficult to say what's happenning without a lot more info, but I
can't help thinking you're making life a lot more difficult than it
needs to be: allow_url_fopen option applies to the file access
wrappers - not fsockopen - but I'd be using the file wrappers method
in preference to implementing my own protocol stack (particularly with
FTP) - but even then I'd prefer to implement it using the curl
library.

When you say it works an FTP client - I assume you are using it
interactively from the command line - try executing it from within
your script (see http://www.php.net/manual/en/ref.exec.php). Note most
versions of the ftp client will happily work with input from a file
redirected to STDIN

C.

Re: FTP unable to connect with fsockopen

am 02.11.2007 18:48:57 von MikeofPet

On Nov 2, 9:45 am, "C. (http://symcbean.blogspot.com/)"
wrote:
> On 2 Nov, 15:28, MikeofPet wrote:
>
> > I am trying to implement FTP in a PHP script but am unable to make the
> > connection to the remote server. The connection step times out at the
> > fsockopen function. I am not sure if it is relevant but PHP is
> > configured with "allow_url_fopen" ON. I am able to do an FTP connect
> > using an FTP client and using the same host/username/password
> > parameters.
>
> > Any ideas would be appreciated.
>
> > Thanks
>
> It's difficult to say what's happenning without a lot more info, but I
> can't help thinking you're making life a lot more difficult than it
> needs to be: allow_url_fopen option applies to the file access
> wrappers - not fsockopen - but I'd be using the file wrappers method
> in preference to implementing my own protocol stack (particularly with
> FTP) - but even then I'd prefer to implement it using the curl
> library.
>
> When you say it works an FTP client - I assume you are using it
> interactively from the command line - try executing it from within
> your script (seehttp://www.php.net/manual/en/ref.exec.php). Note most
> versions of the ftp client will happily work with input from a file
> redirected to STDIN
>
> C.

Thank you for comments - very helpful.

Re: FTP unable to connect with fsockopen

am 02.11.2007 20:00:04 von darko

On Nov 2, 4:28 pm, MikeofPet wrote:
> I am trying to implement FTP in a PHP script but am unable to make the
> connection to the remote server. The connection step times out at the
> fsockopen function. I am not sure if it is relevant but PHP is
> configured with "allow_url_fopen" ON. I am able to do an FTP connect
> using an FTP client and using the same host/username/password
> parameters.
>
> Any ideas would be appreciated.
>
> Thanks

Haven't worked with fsockopen, but I know I hadn't had any problems
with socket_create, socket_connect, gethostbyname, socket_write,
socket_recv, socket_read socket functions family. Maybe you should try
that, it's not so hard. Of course, check if you're opening the correct
port, since it's not a mandatory argument in fsockopen, maybe you
forgot to give the ftp port (it can vary from ftp server to ftp
server, but is often 21, it's standard). Writing php code that relies
on allow_url_fopen maybe isn't that good, since you don't know how
many servers support it.

Re: FTP unable to connect with fsockopen

am 03.11.2007 02:44:27 von Vladimir Ghetau

Mike,

Learn about these two PHP functions:

stream_set_blocking()
stream_set_timeout()

Cheers!

Vladimir
http://www.Vladimirated.com


On Nov 2, 3:28 pm, MikeofPet wrote:
> I am trying to implement FTP in a PHP script but am unable to make the
> connection to the remote server. The connection step times out at the
> fsockopen function. I am not sure if it is relevant but PHP is
> configured with "allow_url_fopen" ON. I am able to do an FTP connect
> using an FTP client and using the same host/username/password
> parameters.
>
> Any ideas would be appreciated.
>
> Thanks