PostgreSQL does not support any source/destination for COPY
other than a file or stdin
/stdout
.
What you can do is COPY
to stdout
and pipe that to a program that writes the data to the ftp dir. psql
's \copy
is useful for this:
psql -c "\copy mytable to stdout with (format csv, header)" | ncftpput -c my.ftp.host /path/on/host
You can use any tool that accepts the input data on a pipe to write to the remote ftp file; ncftpput
is just one option.
A future PostgreSQL version may add support for invoking COPY
with a pipe, e.g. COPY ... TO '|/some/command'
, but there are serious security concerns with running programs under the PostgreSQL user that would make this a superuser-only operation and of questionable safety even then. It's much safer to run the program client-side, and psql
is ideal for that.