Short: B
Long: use-ascii
Help: Use ASCII/text transfer
-Protocols: FTP LDAP
-Category: ftp output ldap
+Protocols: FTP LDAP TFTP
+Category: ftp output ldap tftp
Added: 5.0
Multi: boolean
See-also:
# `--use-ascii`
Enable ASCII transfer mode. For FTP, this can also be enforced by using a URL
-that ends with `;type=A`. This option causes data sent to stdout to be in text
-mode for Win32 systems.
+that ends with `;type=A`. For TFTP, this can also be enforced by using a URL
+that ends with `;mode=netascii`. This option causes data sent to stdout to be
+in text mode for Win32 systems.
static CURLcode tftp_setup_connection(struct Curl_easy *data,
struct connectdata *conn)
{
- char *type;
+ char *path = data->state.up.path;
+ size_t len = strlen(path);
conn->transport_wanted = TRNSPRT_UDP;
- /* TFTP URLs support an extension like ";mode=<typecode>" that
- * we will try to get now! */
- type = strstr(data->state.up.path, ";mode=");
-
- if(!type)
- type = strstr(conn->host.rawalloc, ";mode=");
-
- if(type) {
- char command;
- *type = 0; /* it was in the middle of the hostname */
- command = Curl_raw_toupper(type[6]);
-
- switch(command) {
- case 'A': /* ASCII mode */
- case 'N': /* NETASCII mode */
- data->state.prefer_ascii = TRUE;
- break;
-
- case 'O': /* octet mode */
- case 'I': /* binary mode */
- default:
- /* switch off ASCII */
- data->state.prefer_ascii = FALSE;
- break;
- }
+ /* TFTP URLs support a trailing ";mode=netascii" or ";mode=octet" */
+ if((len >= 14) && !memcmp(&path[len - 14], ";mode=netascii", 14)) {
+ data->state.prefer_ascii = TRUE;
+ path[len - 14] = 0; /* cut it there */
+ }
+ else if((len >= 11) && !memcmp(&path[len - 11], ";mode=octet", 11)) {
+ data->state.prefer_ascii = FALSE;
+ path[len - 11] = 0; /* cut it there */
}
return CURLE_OK;
CURLHELP_HTTP | CURLHELP_POST | CURLHELP_UPLOAD},
{"-B, --use-ascii",
"Use ASCII/text transfer",
- CURLHELP_FTP | CURLHELP_OUTPUT | CURLHELP_LDAP},
+ CURLHELP_FTP | CURLHELP_OUTPUT | CURLHELP_LDAP | CURLHELP_TFTP},
{"-u, --user <user:password>",
"Server user and password",
CURLHELP_IMPORTANT | CURLHELP_AUTH},