Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /trunk/example/example2.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 35 - (hide annotations) (download) (as text)
Sun Mar 1 12:47:31 2009 UTC (15 years, 1 month ago) by hirohitohigashi
File MIME type: text/x-csrc
File size: 2172 byte(s)
added sample programs.

1 hirohitohigashi 35 #include <stdio.h>
2     #include <stdlib.h>
3     #include <string.h>
4     #include <sys/types.h>
5     #include <sys/uio.h>
6     #include <unistd.h>
7    
8     #include "liboftp.h"
9    
10     #define HOSTNAME "YOUR FTP HOSTNAME HERE"
11     #define USERNAME "USER NAME HERE"
12     #define PASSWORD "PASSWORD HERE"
13    
14     int total_err = 0;
15    
16     void err_handle( int err, LIBOFTP *ftp )
17     {
18     printf( "===> error code %d", err );
19     if( err < 0 ) {
20     total_err++;
21     printf( " : %s", ftp->error_message );
22     }
23     printf( "\n\n" );
24     }
25    
26    
27    
28     int main()
29     {
30     LIBOFTP ftp;
31     int err;
32    
33     ftp_initialize( &ftp );
34    
35     printf( "=====[ Connect and login ]=====\n" );
36     printf( "<=== Trying ftp_open()\n" );
37     err = ftp_open( &ftp, HOSTNAME, 0 );
38     err_handle( err, &ftp );
39    
40     printf( "<=== Trying ftp_user()\n" );
41     err = ftp_user( &ftp, USERNAME, PASSWORD );
42     err_handle( err, &ftp );
43    
44     err = ftp_passive( &ftp, 1 );
45    
46     printf( "<=== Trying ftp_type()\n" );
47     err = ftp_type( &ftp, "image" );
48     err_handle( err, &ftp );
49    
50    
51     printf( "<=== Trying ftp_put_descriptor()\n" );
52     err = ftp_put_descriptor( &ftp, "test.txt" );
53     err_handle( err, &ftp );
54     if( err > 0 ) {
55     char *buf[] = { "The quick\n", "brown fox jumps\n", "over the lazy dogs.\n" };
56     int i, fd = err;
57    
58     for( i = 0; i < 3; i++ ) {
59     write( fd, buf[i], strlen( buf[i] ) );
60     }
61    
62     printf( "<=== Trying ftp_put_descriptor_close()\n" );
63     err = ftp_put_descriptor_close( &ftp, fd );
64     err_handle( err, &ftp );
65     }
66    
67     printf( "<=== Trying ftp_get_descriptor()\n" );
68     err = ftp_get_descriptor( &ftp, "test.txt" );
69     err_handle( err, &ftp );
70    
71     if( err > 0 ) {
72     FILE *fp;
73     int fd = err;
74     char buf[256];
75     int n = 1;
76    
77     fp = fdopen( fd, "r" );
78     if( fp == NULL ) {
79     perror( "" );
80     return 1;
81     }
82    
83     printf( "READING...\n" );
84     while( fgets( buf, 256, fp ) ) {
85     printf( "%d: %s", n, buf );
86     n++;
87     }
88     printf( "...DONE\n" );
89     fclose( fp );
90    
91     printf( "<=== Trying ftp_get_descriptor_close()\n" );
92     err = ftp_get_descriptor_close( &ftp, fd );
93     err_handle( err, &ftp );
94     }
95    
96     printf( "<=== Trying ftp_quit()\n" );
97     err = ftp_quit( &ftp );
98     err_handle( err, &ftp );
99    
100     printf( "Total error(s): %d\n", total_err );
101    
102     return 0;
103     }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26