---
name: "Ns_ConnCopyToChannel"
section: "3aolserver"
platform: "linux"
package: "aolserver4-dev"
version: "4.5.1-18.1"
release: "Debian 9 (Stretch)"
platforms: ["linux"]
url: "https://new.carta.tech/Ns_ConnCopyToChannel/3aolserver"
---

# Ns\_ConnCopyToChannel(3aolserver)

Copy request content to open file or dstring

```

```

## NAME

Ns\_ConnCopyToChannel, Ns\_ConnCopyToDString, Ns\_ConnCopyToFd, Ns\_ConnCopyToFile - Copy request content to open file or dstring

## SYNOPSIS

```
#include "ns.h"

int
Ns_ConnCopyToChannel(conn, ncopy, chan)

int
Ns_ConnCopyToDString(conn, ncopy, dsPtr)

int
Ns_ConnCopyToFd(conn, ncopy, fd)

int
Ns_ConnCopyToFile(conn, ncopy, fp)
```

## ARGUMENTS

- Ns\_Channel *chan* (in)

  Pointer to Tcl channel open for write.

- Ns\_Conn *conn* (in)

  Pointer to open connection.

- Ns\_DString *dsPtr* (in)

  Initialized dstring.

- int *fd* (in)

  File descriptor open for write.

- FILE *fp* (in)

  Stdio FILE pointer open for write.

- int *ncopy* (in)

  Number of bytes to copy.

  ```

  ```

## DESCRIPTION

These functions copy content from an open connection request to the given open file descriptor, FILE, dstring, or Tcl\_Channel.  The routines work by copying from the content buffer; see the man page on **Ns\_ConnContent** for how this buffer is managed for both small and large requests.

The functions all return the number of bytes copied which will match the requested *ncopy* argument unless there is an error writing the content or the requested bytes is greater than the number of bytes still available to be read.  An internal offset into the connection is maintained and is shared with routines such as **Ns\_ConnRead** which also consume content from the same buffer. Note that routines which access the entire content, e.g., **Ns\_ConnContent**, **Ns\_ConnContentFd**, or **Ns\_ConnGetQuery** will continue to provide access to the entire request regardless if one of the **Ns\_ConnCopy** or **Ns\_ConnRead** functions have been used.

## EXAMPLES

The following example demonstrates copying user data to a temp file:

```
	fd = open("myfile.out", O_WRONLY|O_BINARY);
	len = Ns_ConnContentLength(conn);
	if (Ns_ConnCopyToFd(conn, len, fd) != len) {
		... error writing content or content already consumed ...
	}
```

## SEE ALSO

[Ns\_ConnRead(3)](/Ns_ConnRead/3.md), [Ns\_ConnReadLine(3)](/Ns_ConnReadLine/3.md), [Ns\_ConnContent(3)](/Ns_ConnContent/3.md), Ns\_ConnContentFd(3)

## KEYWORDS

connection, content, read
