FTP using c/c++ or batch file

I am trying to write a small program that will ftp in c or c++.
I have tried to ftp directly from the c program using a header I found on the interwebs
ftplib.h

I also tried to call a batch file from my ftp program

The program usng ftp lib returns

undefined reference to ftp open

When I try it through my batch file it hangs on

200 port command succesfuls

When I check the directory it makes a directory with my 'mkdir' command
It even upload the file I set it to upload, however the file has 0 bytes.
So if i upload

hello.txt with the letters "Hello Der"

hello.txt will be on the server but it will contain no text

Does ANYONE have experience with ftp'ing using a c or c++ program.

here is my code

C program I found on web

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
> /* example toy application for ftplib 
> 
>    args are: hostname, login, passwd, cddir, lsdir (both possibly as
> empty    strings ""), long?
> 
>    ./example myftpserver mylogin mypassd "" "" 0    ./example
> myftpserver mylogin mypasswd "mydir" "subdir" 1
> 
> */
> 
> #include <stdio.h>
> #include <stdlib.h>
> 
> #include "ftplib.h" int error(char *msg) {   fprintf(stderr, "%s\n", msg);   exit(1); }
> 
> int process_entry(char *ent, unsigned len) {   printf("%s\n", ent);  
> return 0; }
> 
> int main(int argc, char **argv) {   /* this enables printing of sent
> FTP commands */   ftp_debug=1;   /* and this printing of status
> responses */   ftp_verbose=1;
> 
>   /* check number of arguments */   if (argc!=7) error("args");
> 
>   /* open the FTP connection */   if (ftp_open(argv[1], argv[2],
> argv[3])) error("ftp_open");
> 
>   /* perform cd only if a non empty string was given */   if
> (strlen(argv[4])) ftp_cd(argv[4]);
> 
>   /* perform the directory listing */   ftp_ls(atoi(argv[6]), argv[5],
> process_entry);
> 
>   /* the end */   ftp_close(); }
> 

Using This Header




http://christophe.deleuze.free.fr/P/ftplib.h.html


And Here is my second attempt using batch file
I call the file by typing in

testbatch.bat C:\fileToUpload
1
2
3
4
5
6
7
8
> @echo off
> 
> 
> echo user USERNAME> ftpcmd.dat echo PASSWORD>> ftpcmd.dat echo mkdir
> %date:~-4,4%-%date:~-7,2%-%date:~-10,2%-%time:~0,2%>>ftpcmd.dat echo
> cd %date:~-4,4%-%date:~-7,2%-%date:~-10,2%-%time:~0,2%>>ftpcmd.dat
> echo put %1>> ftpcmd.dat echo quit>> ftpcmd.dat ftp -n -s:ftpcmd.dat
> ftp.pyrite.me del ftpcmd.dat


Thanks in advance
Hey, thanks for the quick reply.

Just my running the "example.c" straight out of the box
I was getting
1
2
3
4
 undefined reference to `ftp_open'
undefined reference to `ftp_cd'
undefined reference to `ftp_ls'
undefined reference to `ftp_close'


Even though the following was there.
#include "ftplib.h"

But, I just added
1
2
#include "ftp_var.h"
#include "varsion.h" 


and the

undefined reference to `ftp_open'

went away.

But now it returns..

 
In file included from C:\Documents and Settings\Administrator\Desktop\Programming\example.c:14:


(referring to ftp_var.h)

 
 error: syntax error before "toplevel"


Point out this line in particular in header file "ftp_var.h"

 
Extern sigjmp_buf toplevel;	/* non-local goto stuff for cmd scanner */


Any ideas?

As you can tell, I am pretty new to c.
Last edited on
I started to try to fix all of the errors my compiler was giving me.
Everytime I fix an error it reveals five more.
there are a bunch of header files that need to put into place
in order for
http://christophe.deleuze.free.fr/P/ftplib.h.html

to work. When I find a file that file ended up needing another header file and another. And each header file has error on top of error. then I looked at the
notes and turns out they are over 20 years old. Possibly pre-standard.

There has to be something newer out there.

Anyone?

Topic archived. No new replies allowed.