cURL / Mailing Lists / curl-library / Single Mail

curl-library

Problem in FTP using c# in cURL

From: Amit Kumar Chugh <amit_at_mympo.com>
Date: Thu, 19 May 2005 10:32:10 +0530

Hi To All,

 

I have used this code to send a file to FTP server .every thing is going
fine..but it reads the file byte by byte.so it place the file on FTP serer
and give it a name as (nil) ....Now that's my problem .pls tell how can this
file be save by the same name as it's on client machine....

 

It's my source code..

 

string file=appPath ()+"test.txt";

                  //string FTP="ftp://127.1.1.1/";

                  string FTP="ftp://192.168.0.9/";

                  string User="Anonymous";

                  string Pass="";

                  MessageBox .Show (file);

                  try

                  {

                        Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);

 

 
//Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_SSL);

 

                        FileStream fs = new FileStream(file,
FileMode.Open,FileAccess.Read, FileShare.Read);

                        Easy easy = new Easy();

 

                        Easy.ReadFunction rf = new
Easy.ReadFunction(OnReadData);

                        

 

                        // new Easy.ReadFunction(OnReadData);

                        easy.SetOpt(CURLoption.CURLOPT_READFUNCTION, rf);

                        easy.SetOpt(CURLoption.CURLOPT_READDATA, fs);

                        //easy.SetOpt (CURLoption.CURLOPT_WRITEDATA ,

                        Easy.DebugFunction df = new
Easy.DebugFunction(OnDebug);

                        easy.SetOpt(CURLoption.CURLOPT_DEBUGFUNCTION, df);

                        easy.SetOpt(CURLoption.CURLOPT_VERBOSE, true);

 

                        Easy.ProgressFunction pf = new
Easy.ProgressFunction(OnProgress);

                        easy.SetOpt(CURLoption.CURLOPT_PROGRESSFUNCTION,
pf);

 

                        easy.SetOpt(CURLoption.CURLOPT_URL, FTP);

                        easy.SetOpt(CURLoption.CURLOPT_USERPWD,

                              User + ":" + Pass);

                        easy.SetOpt(CURLoption.CURLOPT_UPLOAD, true);

                        easy.SetOpt(CURLoption.CURLOPT_INFILESIZE,
fs.Length);

                        //easy.SetOpt (CURLoption.CURLOPT_WRITEINFO
,"final.txt");

                        //easy.SetOpt (CURLoption.CURLOPT_WRITEDATA
,"test.txt");

                        //easy.SetOpt (CURLoption.CURLOPT_WRITEFUNCTION
,"wtest.txt");

                        

                        

                        //easy.SetOpt(CURLoption.

 

 

                        

 

                        

                        easy.Perform();

                        

                        

                        easy.Cleanup();

 

                        fs.Close();

 

                        Curl.GlobalCleanup();

                        MessageBox .Show ("Done");

                  }

                  catch(Exception ex)

                  {

                        MessageBox .Show ("Error Occurs"+ex);

                  }

            }

 

            public static Int32 OnReadData(Byte[] buf, Int32 size, Int32
nmemb,

                  Object extraData)

            {

                  FileStream fs = (FileStream)extraData;

                  return fs.Read(buf, 0, size * nmemb);

            }

 

 

            public static void OnDebug(CURLINFOTYPE infoType, String msg,
Object extraData)

            {

                  MessageBox .Show (msg);

            }

 

 

            public static Int32 OnProgress(Object extraData, Double
dlTotal,Double dlNow, Double ulTotal, Double ulNow)

            {

                  MessageBox.Show (dlTotal.ToString () + dlNow.ToString () +
ulTotal.ToString () + ulNow.ToString ());

                  return 0; // standard return from PROGRESSFUNCTION

            }

 

 

 

Thanks in Advance..

Pls reply to amit_at_mympo.com

 

Amit

 
Received on 2005-05-19