/*
* connect to peer at remote host.
*/
if (ftp_prconnect ( &ftpinfo, host ) < 0) {
printf("error: ftp_prconnect failed.\n"
(void) check_n_close ( &ftpinfo, ABNORMAL );
}
/*
* send user name to the remote server.
*/
if (ftp_user( &ftpinfo, "bank" ) < 0) {
printf("error: ftp_user failed.\n"
(void) check_n_close ( &ftpinfo, ABNORMAL );
}
/*
* send user password to the remote server.
*/
if (ftp_passwd ( &ftpinfo, "" ) < 0) {
printf("error: ftp_passwd failed.\n"
(void) check_n_close ( &ftpinfo, ABNORMAL );
}
/*
* set the idle time for this connection.
*/
if (ftp_idle ( &ftpinfo, "7200" ) < 0) {
printf("error: ftp_idle failed.\n"
(void) check_n_close ( &ftpinfo, ABNORMAL );
}
/*
* do a 'cd' on the remote ftp server.
*/
if (ftp_chdir( &ftpinfo, "winnt" ) < 0) {
printf("error: ftp_chdir failed.\n"
(void) check_n_close ( &ftpinfo, ABNORMAL );
}
/*
* do a 'pwd' on the remote ftp server.
*/
if (ftp_pwd ( &ftpinfo ) < 0) {
printf("error: ftp_pwd failed.\n"
(void) check_n_close ( &ftpinfo, ABNORMAL );
}
/*
* set transfer mode to ascii.
*/
if (ftp_ascii ( &ftpinfo ) < 0) {
printf("error: ftp_ascii failed.\n"
(void) check_n_close ( &ftpinfo, ABNORMAL );
}
/*
* set transfer mode to binary.
*/
if (ftp_binary ( &ftpinfo ) < 0) {
printf("error: ftp_binary failed.\n"
(void) check_n_close ( &ftpinfo, ABNORMAL );
}
/*
* set transfer mode back to ascii - using ftp_settype.
*/
if (ftp_settype ( &ftpinfo, ASCII ) < 0) {
printf("error: ftp_settype failed in ascii mode.\n"
(void) check_n_close ( &ftpinfo, ABNORMAL );
}
/*
* set transfer mode back to binary - using ftp_settype.
*/
if (ftp_settype ( &ftpinfo, BINARY ) < 0) {
printf("error: ftp_settype failed in binary mode.\n"
(void) check_n_close ( &ftpinfo, ABNORMAL );
}
/*
* make a directory under /tmp on the server.
*/
if (ftp_mkdir ( &ftpinfo, "prem" ) < 0) {
printf("error: ftp_mkdir failed.\n");
(void) check_n_close ( &ftpinfo, ABNORMAL );
}
/*
* change the mode of the directory created above.
*/
if (ftp_site ( &ftpinfo, "chmod 775 prem" ) < 0) {
printf("error: ftp_site failed.\n");
(void) check_n_close ( &ftpinfo, ABNORMAL );
}
/*
* remove the directory created above.
*/
if (ftp_rmdir ( &ftpinfo, "prem" ) < 0) {
printf("error: ftp_rmdir failed.\n");
(void) check_n_close ( &ftpinfo, ABNORMAL );
}
/*
* use ftp_login to login into the remote ftp server and quit.
*/
if (ftp_login ( &ftpinfo, host, "bank", "", NULL ) < 0) {
printf("error: ftp_login failed.\n");
(void) check_n_close ( &ftpinfo, ABNORMAL );
}
/*
* do a 'put' to the remote host.
*/
if (ftp_putfile ( &ftpinfo, "/tmp/passwd", "c:/passwd" ) < 0) {
printf("error: ftp_putfile failed.\n");
(void) check_n_close ( &ftpinfo, ABNORMAL );
}
else {
printf("transfer speed: \n");
printf("\t\tbytes transferred = %ld\n",
ftpinfo.speed.size_bytes);
printf("\t\ttime taken = %.2g seconds\n",
ftpinfo.speed.seconds);
printf("\t\trate = %.2g Kbytes/s\n",
ftpinfo.speed.kbs);
}
/*
* set transfer mode back to ascii - using ftp_settype.
*/
if (ftp_settype ( &ftpinfo, ASCII ) < 0) {
printf("error: ftp_settype failed in ascii mode.\n");
(void) check_n_close ( &ftpinfo, ABNORMAL );
}
/*
* do a 'get' from the remote host.
*/
if (ftp_getfile ( &ftpinfo, "/tmp/passwd","c:/passwd" )< 0){
printf("error: ftp_getfile failed.\n");
(void) check_n_close ( &ftpinfo, ABNORMAL );
}
else {
printf("transfer speed: \n");
printf("\t\tbytes transferred = %ld\n",
ftpinfo.speed.size_bytes);
printf("\t\ttime taken = %.2g seconds\n",
ftpinfo.speed.seconds);
printf("\t\trate = %.2g Kbytes/s\n",
ftpinfo.speed.kbs);
}
/*
* list /tmp on remote host to file /tmp/test.
*/
if (ftp_dir ( &ftpinfo, "/tmp", "/tmp/test" ) < 0) {
printf("error: ftp_dir failed.\n");
(void) check_n_close ( &ftpinfo, ABNORMAL );
}
/*
* list /tmp on remote host to stdout.
*/
if (ftp_dir ( &ftpinfo, "/tmp", NULL ) < 0) {
printf("error: ftp_dir failed to write to stdout.\n");
(void) check_n_close ( &ftpinfo, ABNORMAL );
}
/*
* delete the file on the remote host.
*/
if (ftp_del ( &ftpinfo, "/tmp/asciifile" ) < 0) {
printf("error: ftp_del failed.\n");
(void) check_n_close ( &ftpinfo, ABNORMAL );
}