29.06.2013 Views

Qshell Interpreter (qsh) - FTP Directory Listing - IBM

Qshell Interpreter (qsh) - FTP Directory Listing - IBM

Qshell Interpreter (qsh) - FTP Directory Listing - IBM

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

* Read the data from the remote shell. */<br />

buf_size = read(sd, ebcdic_buf, DEFAULT_BUF-1);<br />

/* There was a failure reading from the remote shell. */<br />

if (buf_size < 0) {<br />

perror(“\n<strong>qsh</strong>c: error reading data from remote shell”);<br />

printf(“Ended <strong>qsh</strong> session on %s\n”, sysname);<br />

exit(0);<br />

}<br />

/* The remote shell process ended. */<br />

else if (buf_size == 0) {<br />

printf(“\nEnded <strong>qsh</strong> session on %s\n”, sysname);<br />

exit(0);<br />

}<br />

/* Process the data from the remote shell. */<br />

else {<br />

/* Convert to ASCII. */<br />

*(ebcdic_buf+buf_size) = '\0';<br />

if (ConvertToASCII(ebcdic_buf, buf_size+1, ascii_buf,<br />

DEFAULT_BUF) >= 0) {<br />

write(1, ascii_buf, buf_size);<br />

}<br />

}<br />

}<br />

} /* End of while */<br />

exit(0);<br />

} /* End of main() */<br />

/*<br />

* Convert a string from ASCII to EBCDIC.<br />

*/<br />

int<br />

ConvertToEBCDIC(char *ibuf, size_t ileft, char *obuf, size_t oleft)<br />

{<br />

int rc;<br />

#ifdef USE_ICONV<br />

rc = iconv(ecd, (const char**)&ibuf, &ileft, &obuf, &oleft);<br />

#else<br />

rc = Translate((uchar *)ibuf, ileft, (uchar *)obuf, EbcdicTable);<br />

#endif<br />

if (rc < 0)<br />

perror(“<strong>qsh</strong>c: error converting to EBCDIC”);<br />

return rc;<br />

} /* End of ConvertToEBCDIC() */<br />

/*<br />

* Convert a string from EBCDIC to ASCII.<br />

*/<br />

int<br />

ConvertToASCII(char *ibuf, size_t ileft, char *obuf, size_t oleft)<br />

{<br />

int rc;<br />

#ifdef USE_ICONV<br />

rc = iconv(acd, (const char**)&ibuf, &ileft, &obuf, &oleft);<br />

#else<br />

rc = Translate((uchar *)ibuf, ileft, (uchar *)obuf, AsciiTable);<br />

#endif<br />

if (rc < 0)<br />

perror(“<strong>qsh</strong>c: error converting to ASCII”);<br />

return rc;<br />

} /* End of ConvertToASCII() */<br />

/*<br />

* Get the user name and password for the specified system from the<br />

* x/.netrc file.<br />

*/<br />

int<br />

GetPassword(char *sysname, char *logname, char *password)<br />

{<br />

#define BUFSIZE 256<br />

char buffer[BUFSIZE];<br />

Chapter 6. Remote client examples 131

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!