File: v_ftp.c

package info (click to toggle)
vgrabbj 0.9.6-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 708 kB
  • ctags: 297
  • sloc: sh: 2,982; ansic: 2,492; makefile: 71
file content (122 lines) | stat: -rw-r--r-- 3,950 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* Simple Video4Linux image grabber. Made for my Philips Vesta Pro
 * 
 * Copyright (C) 2000, 2001 Robert Wessels, Hengelo, The Netherlands
 * eMail: techie@GrassAndCows.eu.org
 * Certain Changes (C) 2001 Jens Gecius, devel@gecius.de
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at you option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307,
 * USA  
 */


#include "v_ftp.h"

#ifdef LIBFTP

static char mode = 'I';
static netbuf *conn = NULL;

void ftp_upload(struct vconfig *vconf){
  switch(vconf->ftp.state){
    case STATE_UNINITIALIZED:
      FtpInit();
      vconf->ftp.state = STATE_CONNECT;
      v_error(vconf, LOG_INFO, "ftp state 0: upload initialized");
      ftp_upload(vconf);
      break;
    case STATE_CONNECT:
      if(conn)
      	FtpClose(conn);
      if(FtpConnect( vconf->ftp.remoteHost, &conn)){
	if (vconf->ftp.passive) {
      		FtpOptions(FTPLIB_CONNMODE, FTPLIB_PASSIVE, conn);
	} else {
      		FtpOptions(FTPLIB_CONNMODE, FTPLIB_PORT, conn);
	}
        vconf->ftp.state = STATE_LOGIN;
        v_error(vconf, LOG_INFO, "ftp state 1: connection successfull");
      } else {
        v_error(vconf, LOG_WARNING, "ftp state 1: connection failed with reason: %s", FtpLastResponse(conn));
      	return;
      }
      ftp_upload(vconf);
      break;
    case STATE_LOGIN:
      if(FtpLogin( vconf->ftp.username, vconf->ftp.password, conn)){
        vconf->ftp.state = STATE_CHDIR;
        v_error(vconf, LOG_INFO, "ftp state 2: login successfull");
      } else {
        v_error(vconf, LOG_WARNING, "ftp state 2: login failed with reason: %s", FtpLastResponse(conn));
      	return;
      }
      ftp_upload(vconf);
      break;
    case STATE_CHDIR:
      if (vconf->ftp.remoteDir) {
	if(FtpChdir(vconf->ftp.remoteDir, conn)){
	  vconf->ftp.state = STATE_PUT;
	  v_error(vconf, LOG_INFO, "ftp state 3: chdir successfull");
	} else {
	  v_error(vconf, LOG_WARNING, "ftp state 3: chdir failed with reason: %s", FtpLastResponse(conn));
	  return;
	}
      }
      else {
	vconf->ftp.state = STATE_PUT;
	v_error(vconf, LOG_INFO, "fpt state 3: no chdir");
      }
      ftp_upload(vconf);
      break;
    case STATE_PUT:
      if(FtpPut(vconf->out, "vgrabbj.tmp", mode, conn)){
        vconf->ftp.state = STATE_RENAME;
        v_error(vconf, LOG_INFO, "ftp state 4: image upload successfull");
      } else {
        v_error(vconf, LOG_WARNING, "ftp state 4: image upload failed with reason: %s", FtpLastResponse(conn));
      	return;
      }
      ftp_upload(vconf);
      break;
    case STATE_RENAME:
      if(FtpRename("vgrabbj.tmp", vconf->ftp.remoteImageName, conn)){
        vconf->ftp.state = STATE_FINISH;
        v_error(vconf, LOG_INFO, "ftp state 5: rename image successfull");
      } else {
        v_error(vconf, LOG_WARNING, "ftp state 5: rename image failed with reason %s",FtpLastResponse(conn));
      	return;
      }
      ftp_upload(vconf);
      break;
    case STATE_FINISH:
      if(vconf->loop && vconf->ftp.keepalive){
      	vconf->ftp.state = STATE_PUT;
      } else {
	if (conn)
	  FtpClose(conn);
      	vconf->ftp.state = STATE_CONNECT;
      }
      v_error(vconf, LOG_INFO, "ftp state 6: upload compleet");
      break;
    default:
      /* this should never happen */
      	if(conn)
      	  FtpClose(conn);
      	vconf->ftp.state = STATE_CONNECT;
      break;
  }
  return;
}

#endif