📄 prog.c
字号:
if (ftp_rmdir ( &ftpinfo, "prem" ) < 0) {
printf("error: ftp_rmdir failed.\n");
(void) check_n_close ( &ftpinfo, ABNORMAL );
}
/*
* quit the FTP session decently.
*/
if (ftp_bye( &ftpinfo ) < 0) {
printf("error: ftp_bye 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 );
}
/*
* quit the FTP sessions decently.
*/
if (ftp_bye( &ftpinfo ) < 0) {
printf("error: ftp_bye failed.\n");
(void) check_n_close ( &ftpinfo, ABNORMAL );
}
/*
* we're done with our job...so exit the program gracefully.
*/
(void) check_n_close ( &ftpinfo, NORMAL );
}
void
usage(progname)
char *progname;
{
printf("usage: %s <remhost>;\n", progname);
exit (1);
}
void
check_n_close ( ftpinfo, status )
FTPINFO *ftpinfo;
int status;
{
if (ftpinfo ->; sockfd >;= 0)
close (ftpinfo ->; sockfd);
if (status == ABNORMAL)
printf("error: %s\n", ftpinfo ->; ftp_msg);
else
printf("success: %s\n", ftpinfo ->; ftp_msg);
printf("final reply from server: %d\n", ftpinfo ->; reply);
fflush ( stdout );
exit (status);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -