curl-library
doing ftp within a java program using libcurl
Date: Wed, 8 Feb 2006 11:44:55 -0800 (PST)
Hi
I am trying to create a simple prototype where i can do ftp from within my java program using libcurl on windows environment.I have tried out the sample test.java which tests HTTPS protocol and it works fine.
I tried to test FTP protocol after modifying test.java, for some reason it doesn't seem to work.
The cg.perform() statement below seems to return a value of 1 instead of 0 for some reason.
Following is the code which is a modification of test.java:
import org.curl.*;
class testFTP implements CurlWrite {
// static String ca_cert_file = "C:\\eclipse\\plugins\\org.curl_1.0.0\\os\\win32\\x86\\ca-bundle.crt";
static String ca_cert_file = "ca-bundle.crt";
static StringBuffer sbResponse = new StringBuffer(16384);
public int handleString(byte s[])
{
/* output everything */
System.out.println("----------------------------------------");
System.out.println("length : " + s.length);
sbResponse.append(new String(s));
System.out.println("=========================================");
return 0;
}
public static void main(String[] args)
{
CurlGlue cg;
try {
testFTP cw = null;
cg = new CurlGlue();
try {
cg.setopt(CURL.OPT_WRITEFUNCTION, cw);
} catch (CURLException e) {
System.out.println("Wouldn't have thrown an error if we instantiated test() first!");
}
int result = cg.setopt(CURL.OPT_URL, "ftp://ftp.sunet.se/pub/www/utilities/curl/README.curl");
cw = new testFTP();
cg.setopt(CURL.OPT_WRITEFUNCTION, cw);
cg.setopt(CURL.OPT_VERBOSE, 3);
result = cg.perform();
System.out.println("check8 : " + result);
cg.finalize();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("***** OUTPUT STRINGBUFFER *****");
System.out.println("Bytes returned to SB: " + sbResponse.length());
String[] splits = sbResponse.toString().split("\n");
System.out.println("Num lines: " + splits.length);
System.out.println(sbResponse.toString());
}
}
Any suggestions or advise on this will be greatly appreciated.
thanx
alex Picardo
---------------------------------
Relax. Yahoo! Mail virus scanning helps detect nasty viruses!
Received on 2006-02-08