Copying an image from one server to another

Copying an image from one server to another

am 04.02.2008 04:21:16 von John Dillon

I am trying to:

- check whether an image file exists on a server,
- check whether it does not exist on another server, and if not exists
- to copy from the first location to the second.

I am using cURL. First step to capture the image from the first
server. When I return this image to the browser I get a lot of strange
characters. So has this captured the image and what do I use next to
upload to the second server?

I was trying to use file_exists and had problems referencing the file
location as "http://wwww.mysite.com/pic.jpg". But I know I can also
look at using readfile() and file_put_contents(), $fp = fopen(),
fputs(), fpassthru() etc. What is best way?

// create a new cURL resource
$ch = curl_init();
$url="http://wwww.mysite.com/pic.jpg";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);

// copy the handle
$ch2 = curl_copy_handle($ch);

// grab URL and pass it to the browser
curl_exec($ch2);

// close cURL resources, and free up system resources
curl_close($ch2);
curl_close($ch);

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Copying an image from one server to another

am 04.02.2008 05:03:25 von dmagick

ioannes wrote:
> I am trying to:
>
> - check whether an image file exists on a server,
> - check whether it does not exist on another server, and if not exists
> - to copy from the first location to the second.
>
> I am using cURL. First step to capture the image from the first
> server. When I return this image to the browser I get a lot of strange
> characters. So has this captured the image and what do I use next to
> upload to the second server?
>
> I was trying to use file_exists and had problems referencing the file
> location as "http://wwww.mysite.com/pic.jpg". But I know I can also
> look at using readfile() and file_put_contents(), $fp = fopen(),
> fputs(), fpassthru() etc. What is best way?

FTP.

There's no way fopen is going to be able to write to a remote url,
that'd just be such a huge security issue it's not funny.

--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Copying an image from one server to another

am 04.02.2008 09:37:07 von Aleksandar Vojnovic

How about sending the file via SCP? (it would be a much more safer to
transfer files)

-Aleksander

Chris wrote:
> ioannes wrote:
>> I am trying to:
>>
>> - check whether an image file exists on a server,
>> - check whether it does not exist on another server, and if not exists
>> - to copy from the first location to the second.
>>
>> I am using cURL. First step to capture the image from the first
>> server. When I return this image to the browser I get a lot of
>> strange characters. So has this captured the image and what do I use
>> next to upload to the second server?
>>
>> I was trying to use file_exists and had problems referencing the file
>> location as "http://wwww.mysite.com/pic.jpg". But I know I can also
>> look at using readfile() and file_put_contents(), $fp = fopen(),
>> fputs(), fpassthru() etc. What is best way?
>
> FTP.
>
> There's no way fopen is going to be able to write to a remote url,
> that'd just be such a huge security issue it's not funny.
>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Copying an image from one server to another

am 04.02.2008 17:03:33 von parasane

On Feb 3, 2008 11:03 PM, Chris wrote:
> FTP.
>
> There's no way fopen is going to be able to write to a remote url,
> that'd just be such a huge security issue it's not funny.

I must've missed when the W3C and IETF forced a disable on POST. ;-P

--


Daniel P. Brown
Senior Unix Geek


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Copying an image from one server to another

am 04.02.2008 17:05:05 von parasane

On Feb 4, 2008 11:03 AM, Daniel Brown wrote:
> On Feb 3, 2008 11:03 PM, Chris wrote:
> > FTP.
> >
> > There's no way fopen is going to be able to write to a remote url,
> > that'd just be such a huge security issue it's not funny.
>
> I must've missed when the W3C and IETF forced a disable on POST. ;-P

Whoops! I must've also missed reading comprehension in school. I
glanced over it too quickly and missed the specific reference to
fopen(). Sorry!

--


Daniel P. Brown
Senior Unix Geek


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Copying an image from one server to another

am 04.02.2008 18:58:45 von John Dillon

Initially I could not find much on SCP and rsynch is about synchronising
folders, but that is only part of the problem. I don't want files in
the target location that are not referenced from the target database. I
hold references like this

img[]=pic1.jpg&img[]=pic2.jpg

then I parse it out into the img array.

So I want to do it from php programming and am on a shared server. I
may have access to the terminal for linux/unix but I am not too strong
in that area. So am I wrong to be still thinking of cURL?

John

Aleksandar Vojnovic wrote:
> How about sending the file via SCP? (it would be a much more safer to
> transfer files)
>
> -Aleksander
>
> Chris wrote:
>> ioannes wrote:
>>> I am trying to:
>>>
>>> - check whether an image file exists on a server,
>>> - check whether it does not exist on another server, and if not exists
>>> - to copy from the first location to the second.
>>>
>>> I am using cURL. First step to capture the image from the first
>>> server. When I return this image to the browser I get a lot of
>>> strange characters. So has this captured the image and what do I
>>> use next to upload to the second server?
>>>
>>> I was trying to use file_exists and had problems referencing the
>>> file location as "http://wwww.mysite.com/pic.jpg". But I know I can
>>> also look at using readfile() and file_put_contents(), $fp =
>>> fopen(), fputs(), fpassthru() etc. What is best way?
>>
>> FTP.
>>
>> There's no way fopen is going to be able to write to a remote url,
>> that'd just be such a huge security issue it's not funny.
>>
>
>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Copying an image from one server to another

am 04.02.2008 19:41:58 von Captain Webber

Note the rsync option:

--include-from=FILE
This option is related to the --include option, but it specifies
a FILE that contains include patterns (one per line). Blank
lines in the file and lines starting with ';' or '#' are ignored. If
FILE is -, the list will be read from standard input.

So, from a PhpScript, you manage the contents of "FILE" and then launch
rsync with the appropriate additional options.

-----Original Message-----
From: ioannes [mailto:ioannes@btinternet.com]
Sent: Monday, February 04, 2008 12:59 PM
To: php-db@lists.php.net
Subject: Re: [PHP-DB] Copying an image from one server to another

Initially I could not find much on SCP and rsynch is about synchronising
folders, but that is only part of the problem. I don't want files in
the target location that are not referenced from the target database. I
hold references like this

img[]=pic1.jpg&img[]=pic2.jpg

then I parse it out into the img array.

So I want to do it from php programming and am on a shared server. I
may have access to the terminal for linux/unix but I am not too strong
in that area. So am I wrong to be still thinking of cURL?

John

Aleksandar Vojnovic wrote:
> How about sending the file via SCP? (it would be a much more safer to
> transfer files)
>
> -Aleksander
>
> Chris wrote:
>> ioannes wrote:
>>> I am trying to:
>>>
>>> - check whether an image file exists on a server,
>>> - check whether it does not exist on another server, and if not exists
>>> - to copy from the first location to the second.
>>>
>>> I am using cURL. First step to capture the image from the first
>>> server. When I return this image to the browser I get a lot of
>>> strange characters. So has this captured the image and what do I
>>> use next to upload to the second server?
>>>
>>> I was trying to use file_exists and had problems referencing the
>>> file location as "http://wwww.mysite.com/pic.jpg". But I know I can
>>> also look at using readfile() and file_put_contents(), $fp =
>>> fopen(), fputs(), fpassthru() etc. What is best way?
>>
>> FTP.
>>
>> There's no way fopen is going to be able to write to a remote url,
>> that'd just be such a huge security issue it's not funny.
>>
>
>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Copying an image from one server to another

am 05.02.2008 00:07:40 von dmagick

Aleksandar Vojnovic wrote:
> How about sending the file via SCP? (it would be a much more safer to
> transfer files)

SFTP will work nicely though I don't know if there's a native SCP type
function in php. I know there is the pecl library but that's not going
to be available in most places (but again it depends on what the OP's
trying to do and if it's meant to run in a shared or dedicated environment).

> Chris wrote:
>> ioannes wrote:
>>> I am trying to:
>>>
>>> - check whether an image file exists on a server,
>>> - check whether it does not exist on another server, and if not exists
>>> - to copy from the first location to the second.
>>>
>>> I am using cURL. First step to capture the image from the first
>>> server. When I return this image to the browser I get a lot of
>>> strange characters. So has this captured the image and what do I use
>>> next to upload to the second server?
>>>
>>> I was trying to use file_exists and had problems referencing the file
>>> location as "http://wwww.mysite.com/pic.jpg". But I know I can also
>>> look at using readfile() and file_put_contents(), $fp = fopen(),
>>> fputs(), fpassthru() etc. What is best way?
>>
>> FTP.
>>
>> There's no way fopen is going to be able to write to a remote url,
>> that'd just be such a huge security issue it's not funny.
>>
>
>


--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Copying an image from one server to another

am 05.02.2008 05:10:34 von John Dillon

This is too advanced for me and having spent several hours reading I am
no wiser. Given that I understand cURL and uploading files is possible
- http://us3.php.net/features.file-upload - it should be just a matter
of referencing a .jpg using a URL into a variable and uploading it to
the target server, but from a script rather than a web form. Would
file() work as the documentation seems to refer to text files that are
read line by line. http://us3.php.net/manual/en/function.file.php

John

Chris wrote:
> Aleksandar Vojnovic wrote:
>> How about sending the file via SCP? (it would be a much more safer to
>> transfer files)
>
> SFTP will work nicely though I don't know if there's a native SCP type
> function in php. I know there is the pecl library but that's not going
> to be available in most places (but again it depends on what the OP's
> trying to do and if it's meant to run in a shared or dedicated
> environment).
>
>> Chris wrote:
>>> ioannes wrote:
>>>> I am trying to:
>>>>
>>>> - check whether an image file exists on a server,
>>>> - check whether it does not exist on another server, and if not exists
>>>> - to copy from the first location to the second.
>>>>
>>>> I am using cURL. First step to capture the image from the first
>>>> server. When I return this image to the browser I get a lot of
>>>> strange characters. So has this captured the image and what do I
>>>> use next to upload to the second server?
>>>>
>>>> I was trying to use file_exists and had problems referencing the
>>>> file location as "http://wwww.mysite.com/pic.jpg". But I know I
>>>> can also look at using readfile() and file_put_contents(), $fp =
>>>> fopen(), fputs(), fpassthru() etc. What is best way?
>>>
>>> FTP.
>>>
>>> There's no way fopen is going to be able to write to a remote url,
>>> that'd just be such a huge security issue it's not funny.
>>>
>>
>>
>
>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Copying an image from one server to another

am 05.02.2008 05:24:51 von dmagick

ioannes wrote:
> This is too advanced for me and having spent several hours reading I am
> no wiser. Given that I understand cURL and uploading files is possible
> - http://us3.php.net/features.file-upload - it should be just a matter
> of referencing a .jpg using a URL into a variable and uploading it to
> the target server, but from a script rather than a web form. Would
> file() work as the documentation seems to refer to text files that are
> read line by line. http://us3.php.net/manual/en/function.file.php

You cannot use file or fputs to WRITE to a url or remote server.

You will have to find another way (one being ftp: http://www.php.net/ftp).

--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Copying an image from one server to another

am 05.02.2008 15:48:22 von John Dillon

I was unsure what was meant by FILE in php - is that the global? How do
I reference a remote site's jpg file into FILE? Then how to I create
the output from the php into stdout - using the return of a function?
or print? Then how to launch rsynch - I understand how to call it from
cron, as my web server kindly gives me an interface for this, but to
create the file I would need to know what extension to save with the
script name, and how to make it execute, ie the equivalent of rsynch scripts. Then how is FILE read by rsynch script. So lots more
questions just to copy a publicly available image into my site. There
has got to be an easier way.

John

Mr Webber wrote:
> Note the rsync option:
>
> --include-from=FILE
> This option is related to the --include option, but it specifies
> a FILE that contains include patterns (one per line). Blank
> lines in the file and lines starting with ';' or '#' are ignored. If
> FILE is -, the list will be read from standard input.
>
> So, from a PhpScript, you manage the contents of "FILE" and then launch
> rsync with the appropriate additional options.
>
> -----Original Message-----
> From: ioannes [mailto:ioannes@btinternet.com]
> Sent: Monday, February 04, 2008 12:59 PM
> To: php-db@lists.php.net
> Subject: Re: [PHP-DB] Copying an image from one server to another
>
> Initially I could not find much on SCP and rsynch is about synchronising
> folders, but that is only part of the problem. I don't want files in
> the target location that are not referenced from the target database. I
> hold references like this
>
> img[]=pic1.jpg&img[]=pic2.jpg
>
> then I parse it out into the img array.
>
> So I want to do it from php programming and am on a shared server. I
> may have access to the terminal for linux/unix but I am not too strong
> in that area. So am I wrong to be still thinking of cURL?
>
> John
>
> Aleksandar Vojnovic wrote:
>
>> How about sending the file via SCP? (it would be a much more safer to
>> transfer files)
>>
>> -Aleksander
>>
>> Chris wrote:
>>
>>> ioannes wrote:
>>>
>>>> I am trying to:
>>>>
>>>> - check whether an image file exists on a server,
>>>> - check whether it does not exist on another server, and if not exists
>>>> - to copy from the first location to the second.
>>>>
>>>> I am using cURL. First step to capture the image from the first
>>>> server. When I return this image to the browser I get a lot of
>>>> strange characters. So has this captured the image and what do I
>>>> use next to upload to the second server?
>>>>
>>>> I was trying to use file_exists and had problems referencing the
>>>> file location as "http://wwww.mysite.com/pic.jpg". But I know I can
>>>> also look at using readfile() and file_put_contents(), $fp =
>>>> fopen(), fputs(), fpassthru() etc. What is best way?
>>>>
>>> FTP.
>>>
>>> There's no way fopen is going to be able to write to a remote url,
>>> that'd just be such a huge security issue it's not funny.
>>>
>>>
>>
>
>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Copying an image from one server to another

am 05.02.2008 15:49:06 von John Dillon

OK but I could execute the script on the target server, which is also
mine. So the jpg on the source is actually the remote server, I would
be reading a remote file and writing it to the server which is executing
the script.

Chris wrote:
> ioannes wrote:
>> This is too advanced for me and having spent several hours reading I
>> am no wiser. Given that I understand cURL and uploading files is
>> possible - http://us3.php.net/features.file-upload - it should be
>> just a matter of referencing a .jpg using a URL into a variable and
>> uploading it to the target server, but from a script rather than a
>> web form. Would file() work as the documentation seems to refer to
>> text files that are read line by line.
>> http://us3.php.net/manual/en/function.file.php
>
> You cannot use file or fputs to WRITE to a url or remote server.
>
> You will have to find another way (one being ftp:
> http://www.php.net/ftp).
>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Copying an image from one server to another

am 05.02.2008 19:21:56 von John Dillon

I am and have been reading http://samba.org/ftp/rsync/rsync.html, which
is one web page but 44 real pages. I see that FILE is a term used the
rsynch script. Is this something output from the php script, and if so
how is it channelled from one to the other?

I see the following:

- start quote -
****

**--exclude-from=FILE**
This option is related to the *--exclude* option, but it specifies a
FILE that contains exclude patterns (one per line). Blank lines in
the file and lines starting with ';' or '#' are ignored. If /FILE/
is *-*, the list will be read from standard input.

**--include-from=FILE**

This option is related to the *--include* option, but it specifies a
FILE that contains include patterns (one per line). Blank lines in
the file and lines starting with ';' or '#' are ignored. If /FILE/
is *-*, the list will be read from standard input.

**--files-from=FILE**
Using this option allows you to specify the exact list of files to
transfer (as read from the specified FILE or *-* for standard
input). It also tweaks the default behavior of rsync to make
transferring just the specified files and directories easier:

* The *--relative* (*-R*) option is implied, which preserves
the path information that is specified for each item in
the file (use *--no-relative* or *--no-R* if you want to
turn that off).
* The *--dirs* (*-d*) option is implied, which will create
directories specified in the list on the destination
rather than noisily skipping them (use *--no-dirs* or
*--no-d* if you want to turn that off).
* The *--archive* (*-a*) option's behavior does not imply
*--recursive* (*-r*), so specify it explicitly, if you
want it.
* These side-effects change the default state of rsync, so
the position of the *--files-from* option on the
command-line has no bearing on how other options are
parsed (e.g. *-a* works the same before or after
*--files-from*, as does *--no-R* and all other options).

The filenames that are read from the FILE are all relative to the
source dir -- any leading slashes are removed and no ".." references
are allowed to go higher than the source dir. For example, take this
command:

|rsync -a --files-from=/tmp/foo /usr remote:/backup|

If /tmp/foo contains the string "bin" (or even "/bin"), the /usr/bin
directory will be created as /backup/bin on the remote host. If it
contains "bin/" (note the trailing slash), the immediate contents of
the directory would also be sent (without needing to be explicitly
mentioned in the file -- this began in version 2.6.4). In both
cases, if the *-r* option was enabled, that dir's entire hierarchy
would also be transferred (keep in mind that *-r* needs to be
specified explicitly with *--files-from*, since it is not implied by
*-a*). Also note that the effect of the (enabled by default)
*--relative* option is to duplicate only the path info that is read
from the file -- it does not force the duplication of the
source-spec path (/usr in this case).

In addition, the *--files-from* file can be read from the remote
host instead of the local host if you specify a "host:" in front of
the file (the host must match one end of the transfer). As a
short-cut, you can specify just a prefix of ":" to mean "use the
remote end of the transfer". For example:

|rsync -a --files-from=:/path/file-list src:/ /tmp/copy|

This would copy all the files specified in the /path/file-list file
that was located on the remote "src" host.

- end quote -

but I don't understand anything really from the synopsis:

- start quote -


SYNOPSIS

Local: rsync [OPTION...] SRC... [DEST]

Access via remote shell:
Pull: rsync [OPTION...] [USER@]HOST:SRC... [DEST]
Push: rsync [OPTION...] SRC... [USER@]HOST:DEST

Access via rsync daemon:
Pull: rsync [OPTION...] [USER@]HOST::SRC... [DEST]
rsync [OPTION...] rsync://[USER@]HOST[:PORT]/SRC... [DEST]
Push: rsync [OPTION...] SRC... [USER@]HOST::DEST
rsync [OPTION...] SRC... rsync://[USER@]HOST[:PORT]/DEST

- end quote -

What is push and pull?

I am guessing I might achieve something by writing a rsynch script with
lines like:

|rsync -avz foo:src/bar/ /data/tmp

save it as rsynch.txt and call it from a cron job. I don't understand
how I build up a file list of the jpgs I want to copy. Patterns will
not do it. I need to create an array from the database and get those
files into the new site.

John
|

Mr Webber wrote:
> FILE is there reference from the man page. It contains the files to include
> in the sync.
>
> Have you read the man page for rsync?
>
> -----Original Message-----
> From: ioannes [mailto:ioannes@btinternet.com]
> Sent: Tuesday, February 05, 2008 9:48 AM
> To: php-db@lists.php.net
> Subject: Re: [PHP-DB] Copying an image from one server to another
>
> I was unsure what was meant by FILE in php - is that the global? How do
> I reference a remote site's jpg file into FILE? Then how to I create
> the output from the php into stdout - using the return of a function?
> or print? Then how to launch rsynch - I understand how to call it from
> cron, as my web server kindly gives me an interface for this, but to
> create the file I would need to know what extension to save with the
> script name, and how to make it execute, ie the equivalent of > rsynch scripts. Then how is FILE read by rsynch script. So lots more
> questions just to copy a publicly available image into my site. There
> has got to be an easier way.
>
> John
>
> Mr Webber wrote:
>
>> Note the rsync option:
>>
>> --include-from=FILE
>> This option is related to the --include option, but it
>>
> specifies
>
>> a FILE that contains include patterns (one per line). Blank
>> lines in the file and lines starting with ';' or '#' are ignored.
>>
> If
>
>> FILE is -, the list will be read from standard input.
>>
>> So, from a PhpScript, you manage the contents of "FILE" and then launch
>> rsync with the appropriate additional options.
>>
>> -----Original Message-----
>> From: ioannes [mailto:ioannes@btinternet.com]
>> Sent: Monday, February 04, 2008 12:59 PM
>> To: php-db@lists.php.net
>> Subject: Re: [PHP-DB] Copying an image from one server to another
>>
>> Initially I could not find much on SCP and rsynch is about synchronising
>> folders, but that is only part of the problem. I don't want files in
>> the target location that are not referenced from the target database. I
>> hold references like this
>>
>> img[]=pic1.jpg&img[]=pic2.jpg
>>
>> then I parse it out into the img array.
>>
>> So I want to do it from php programming and am on a shared server. I
>> may have access to the terminal for linux/unix but I am not too strong
>> in that area. So am I wrong to be still thinking of cURL?
>>
>> John
>>
>> Aleksandar Vojnovic wrote:
>>
>>
>>> How about sending the file via SCP? (it would be a much more safer to
>>> transfer files)
>>>
>>> -Aleksander
>>>
>>> Chris wrote:
>>>
>>>
>>>> ioannes wrote:
>>>>
>>>>
>>>>> I am trying to:
>>>>>
>>>>> - check whether an image file exists on a server,
>>>>> - check whether it does not exist on another server, and if not exists
>>>>> - to copy from the first location to the second.
>>>>>
>>>>> I am using cURL. First step to capture the image from the first
>>>>> server. When I return this image to the browser I get a lot of
>>>>> strange characters. So has this captured the image and what do I
>>>>> use next to upload to the second server?
>>>>>
>>>>> I was trying to use file_exists and had problems referencing the
>>>>> file location as "http://wwww.mysite.com/pic.jpg". But I know I can
>>>>> also look at using readfile() and file_put_contents(), $fp =
>>>>> fopen(), fputs(), fpassthru() etc. What is best way?
>>>>>
>>>>>
>>>> FTP.
>>>>
>>>> There's no way fopen is going to be able to write to a remote url,
>>>> that'd just be such a huge security issue it's not funny.
>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Copying an image from one server to another

am 05.02.2008 19:24:30 von parasane

On Feb 5, 2008 9:49 AM, ioannes wrote:
> OK but I could execute the script on the target server, which is also
> mine. So the jpg on the source is actually the remote server, I would
> be reading a remote file and writing it to the server which is executing
> the script.

Then you could do something like this:

$filename = "http://www.remote.come/image.jpg";
exec('wget '.$filename);
?>

As always, sanitizing and customizing are up to you.

--


Daniel P. Brown
Senior Unix Geek


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Copying an image from one server to another

am 05.02.2008 19:56:06 von Captain Webber

The pattern in you --include-from=FILE_CONTAINING_FILENAME_PATTERNS could be
just a list of files that you can generate from your PhpScript. Get it now?

-----Original Message-----
From: ioannes [mailto:ioannes@btinternet.com]
Sent: Tuesday, February 05, 2008 1:22 PM
To: php-db@lists.php.net
Subject: Re: [PHP-DB] Copying an image from one server to another

I am and have been reading http://samba.org/ftp/rsync/rsync.html, which
is one web page but 44 real pages. I see that FILE is a term used the
rsynch script. Is this something output from the php script, and if so
how is it channelled from one to the other?

I see the following:

- start quote -
****

**--exclude-from=FILE**
This option is related to the *--exclude* option, but it specifies a
FILE that contains exclude patterns (one per line). Blank lines in
the file and lines starting with ';' or '#' are ignored. If /FILE/
is *-*, the list will be read from standard input.

**--include-from=FILE**

This option is related to the *--include* option, but it specifies a
FILE that contains include patterns (one per line). Blank lines in
the file and lines starting with ';' or '#' are ignored. If /FILE/
is *-*, the list will be read from standard input.

**--files-from=FILE**
Using this option allows you to specify the exact list of files to
transfer (as read from the specified FILE or *-* for standard
input). It also tweaks the default behavior of rsync to make
transferring just the specified files and directories easier:

* The *--relative* (*-R*) option is implied, which preserves
the path information that is specified for each item in
the file (use *--no-relative* or *--no-R* if you want to
turn that off).
* The *--dirs* (*-d*) option is implied, which will create
directories specified in the list on the destination
rather than noisily skipping them (use *--no-dirs* or
*--no-d* if you want to turn that off).
* The *--archive* (*-a*) option's behavior does not imply
*--recursive* (*-r*), so specify it explicitly, if you
want it.
* These side-effects change the default state of rsync, so
the position of the *--files-from* option on the
command-line has no bearing on how other options are
parsed (e.g. *-a* works the same before or after
*--files-from*, as does *--no-R* and all other options).

The filenames that are read from the FILE are all relative to the
source dir -- any leading slashes are removed and no ".." references
are allowed to go higher than the source dir. For example, take this
command:

|rsync -a --files-from=/tmp/foo /usr remote:/backup|

If /tmp/foo contains the string "bin" (or even "/bin"), the /usr/bin
directory will be created as /backup/bin on the remote host. If it
contains "bin/" (note the trailing slash), the immediate contents of
the directory would also be sent (without needing to be explicitly
mentioned in the file -- this began in version 2.6.4). In both
cases, if the *-r* option was enabled, that dir's entire hierarchy
would also be transferred (keep in mind that *-r* needs to be
specified explicitly with *--files-from*, since it is not implied by
*-a*). Also note that the effect of the (enabled by default)
*--relative* option is to duplicate only the path info that is read
from the file -- it does not force the duplication of the
source-spec path (/usr in this case).

In addition, the *--files-from* file can be read from the remote
host instead of the local host if you specify a "host:" in front of
the file (the host must match one end of the transfer). As a
short-cut, you can specify just a prefix of ":" to mean "use the
remote end of the transfer". For example:

|rsync -a --files-from=:/path/file-list src:/ /tmp/copy|

This would copy all the files specified in the /path/file-list file
that was located on the remote "src" host.

- end quote -

but I don't understand anything really from the synopsis:

- start quote -


SYNOPSIS

Local: rsync [OPTION...] SRC... [DEST]

Access via remote shell:
Pull: rsync [OPTION...] [USER@]HOST:SRC... [DEST]
Push: rsync [OPTION...] SRC... [USER@]HOST:DEST

Access via rsync daemon:
Pull: rsync [OPTION...] [USER@]HOST::SRC... [DEST]
rsync [OPTION...] rsync://[USER@]HOST[:PORT]/SRC... [DEST]
Push: rsync [OPTION...] SRC... [USER@]HOST::DEST
rsync [OPTION...] SRC... rsync://[USER@]HOST[:PORT]/DEST

- end quote -

What is push and pull?

I am guessing I might achieve something by writing a rsynch script with
lines like:

|rsync -avz foo:src/bar/ /data/tmp

save it as rsynch.txt and call it from a cron job. I don't understand
how I build up a file list of the jpgs I want to copy. Patterns will
not do it. I need to create an array from the database and get those
files into the new site.

John
|

Mr Webber wrote:
> FILE is there reference from the man page. It contains the files to
include
> in the sync.
>
> Have you read the man page for rsync?
>
> -----Original Message-----
> From: ioannes [mailto:ioannes@btinternet.com]
> Sent: Tuesday, February 05, 2008 9:48 AM
> To: php-db@lists.php.net
> Subject: Re: [PHP-DB] Copying an image from one server to another
>
> I was unsure what was meant by FILE in php - is that the global? How do
> I reference a remote site's jpg file into FILE? Then how to I create
> the output from the php into stdout - using the return of a function?
> or print? Then how to launch rsynch - I understand how to call it from
> cron, as my web server kindly gives me an interface for this, but to
> create the file I would need to know what extension to save with the
> script name, and how to make it execute, ie the equivalent of > rsynch scripts. Then how is FILE read by rsynch script. So lots more
> questions just to copy a publicly available image into my site. There
> has got to be an easier way.
>
> John
>
> Mr Webber wrote:
>
>> Note the rsync option:
>>
>> --include-from=FILE
>> This option is related to the --include option, but it
>>
> specifies
>
>> a FILE that contains include patterns (one per line). Blank
>> lines in the file and lines starting with ';' or '#' are ignored.
>>
> If
>
>> FILE is -, the list will be read from standard input.
>>
>> So, from a PhpScript, you manage the contents of "FILE" and then launch
>> rsync with the appropriate additional options.
>>
>> -----Original Message-----
>> From: ioannes [mailto:ioannes@btinternet.com]
>> Sent: Monday, February 04, 2008 12:59 PM
>> To: php-db@lists.php.net
>> Subject: Re: [PHP-DB] Copying an image from one server to another
>>
>> Initially I could not find much on SCP and rsynch is about synchronising
>> folders, but that is only part of the problem. I don't want files in
>> the target location that are not referenced from the target database. I
>> hold references like this
>>
>> img[]=pic1.jpg&img[]=pic2.jpg
>>
>> then I parse it out into the img array.
>>
>> So I want to do it from php programming and am on a shared server. I
>> may have access to the terminal for linux/unix but I am not too strong
>> in that area. So am I wrong to be still thinking of cURL?
>>
>> John
>>
>> Aleksandar Vojnovic wrote:
>>
>>
>>> How about sending the file via SCP? (it would be a much more safer to
>>> transfer files)
>>>
>>> -Aleksander
>>>
>>> Chris wrote:
>>>
>>>
>>>> ioannes wrote:
>>>>
>>>>
>>>>> I am trying to:
>>>>>
>>>>> - check whether an image file exists on a server,
>>>>> - check whether it does not exist on another server, and if not exists
>>>>> - to copy from the first location to the second.
>>>>>
>>>>> I am using cURL. First step to capture the image from the first
>>>>> server. When I return this image to the browser I get a lot of
>>>>> strange characters. So has this captured the image and what do I
>>>>> use next to upload to the second server?
>>>>>
>>>>> I was trying to use file_exists and had problems referencing the
>>>>> file location as "http://wwww.mysite.com/pic.jpg". But I know I can
>>>>> also look at using readfile() and file_put_contents(), $fp =
>>>>> fopen(), fputs(), fpassthru() etc. What is best way?
>>>>>
>>>>>
>>>> FTP.
>>>>
>>>> There's no way fopen is going to be able to write to a remote url,
>>>> that'd just be such a huge security issue it's not funny.
>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Copying an image from one server to another

am 05.02.2008 20:33:42 von John Dillon

OK, so how would I hand over the list of files from php to the script?
And am I right that I would write the rsynch code in a text file called
anything.txt and the

rsync

at the start of the line is what calls up the rsynch program, unlike php
where you need to call it something.php - though I have never questioned
that assumption.

Or is there a way to call rsynch from the same scrpit that php is in? I
can't visualise it.

John


John

Mr Webber wrote:
> The pattern in you --include-from=FILE_CONTAINING_FILENAME_PATTERNS could be
> just a list of files that you can generate from your PhpScript. Get it now?
>
> --
>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Copying an image from one server to another

am 05.02.2008 20:57:51 von John Dillon

Am I right in thinking that exec() executes a string as a call to a
program which executes in a shell? So am I to write:

$callthis="the contents of my rsynch file";
exec($callthis);

?

John


ioannes wrote:
> OK, so how would I hand over the list of files from php to the
> script? And am I right that I would write the rsynch code in a text
> file called anything.txt and the
>
> rsync
> at the start of the line is what calls up the rsynch program, unlike
> php where you need to call it something.php - though I have never
> questioned that assumption.
> Or is there a way to call rsynch from the same scrpit that php is in?
> I can't visualise it.
>
> John
>
>
> John
>
> Mr Webber wrote:
>> The pattern in you --include-from=FILE_CONTAINING_FILENAME_PATTERNS
>> could be
>> just a list of files that you can generate from your PhpScript. Get
>> it now?
>>
>> --
>>
>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Copying an image from one server to another

am 05.02.2008 21:08:07 von parasane

On Feb 5, 2008 2:57 PM, ioannes wrote:
> Am I right in thinking that exec() executes a string as a call to a
> program which executes in a shell? So am I to write:
>
> $callthis="the contents of my rsynch file";
> exec($callthis);

Filtered.... :-\

--


Daniel P. Brown
Senior Unix Geek


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Copying an image from one server to another

am 05.02.2008 23:38:20 von dmagick

ioannes wrote:
> OK but I could execute the script on the target server, which is also
> mine. So the jpg on the source is actually the remote server, I would
> be reading a remote file and writing it to the server which is executing
> the script.

OK I guess i completely misunderstood what you were doing then (and I
guess everyone else did too :P).

easy.

$remote_image = file_get_contents('http://domain.com/image.jpg');
file_put_contents('/path/to/image/folder/image.jpg');

or if it's a big image use fopen, fputs, fclose (read the manual for
using these).

--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php