tags:

views:

14

answers:

1

I realize that there are other more straightforward ways to conduct FTP. However, I have a specific need to be able to use fopen on a file via FTP. The following code works just great:

$FTP="ftp://$FTPUser:$FTPPass@$FTPHost/$file_dest";
$fp=fopen($FTP, 'w');

The problem is when the path of the $file_dest is invalid. For example if $file_dest="1/2/3/test.txt".

If the 1, 2, or 3 folders do not exist, then it takes 90 seconds for the fopen to fail.

How can I reduce this timeout?

A: 

I would have suggested creating a stream context, but as you say, there seems to be no timeout option for the FTP protocol there.

Try whether the default_socket_timeout option as suggested here applies to FTP operations - I'm not entirely sure.

If that doesn't work out, I'm not sure whether you don't have to resort to the proper FTP functions, which definitely allow for setting a timeout.

Pekka
The webhost server that I'm ftping from doesn't have disk io privlidges, so I can't read from the disk. I have access only to the filecontents posted via http. ftp_put fails because the source content is a file, not a string. Lots of web-hosts deny file io (yet fully support ftp!), so I need to cover this case.
Joshua
@Joshua how about using a data wrapper as a file resource and reading from that? http://www.php.net/manual/en/wrappers.data.php
Pekka