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 succesful
s
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