cURL / Mailing Lists / curl-library / Single Mail

curl-library

How to change directory path in FTP server

From: Mohd Idzuan <idzuan_at_gmail.com>
Date: Wed, 12 Apr 2006 14:39:24 +0800

Hi,

I have successfully connected to FTP server using
the libcurl.NET library in C#. My problem is, how to
change directory in the FTP server, before i can start
uploading files. I managed to returned the root directory
of the FTP server using

easy.SetOpt(CURLoption.CURLOPT_FTPLISTONLY, true);

, but i wonder how to change to other folder in the FTP server.
My C# ftp client should be able to flexibily change current working folder
as requested by the user.

Below is my coding that i use to connect to the FTP server, TQ :

using System;
using System.Collections.Generic;
using System.Text;
using SeasideResearch.LibCurlNet;

namespace ftpcmd
{
    class ftp
    {
        static void Main(string[] args)
        {
            //Init global curl library
            Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);

            //Create Easy handle
            Easy easy = new Easy();

            //Create FTP command handle
            Slist slist = new Slist();

            //Get Returned messages from server
            Easy.WriteFunction wf = new Easy.WriteFunction(OnWriteData);
            easy.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf);

            //Debug Function
            Easy.DebugFunction df = new Easy.DebugFunction(OnDebug);
            easy.SetOpt(CURLoption.CURLOPT_DEBUGFUNCTION, df);

            //Set verbose whatever messages returned to true
            easy.SetOpt(CURLoption.CURLOPT_VERBOSE, true);

            //Login FTP
            easy.SetOpt(CURLoption.CURLOPT_USERPWD,"
anonymous:idzuan_at_gmail.com");

            //FTP Url
            easy.SetOpt(CURLoption.CURLOPT_URL,"ftp.jaring.my");

            // use passive FTP, if it's available
            easy.SetOpt(CURLoption.CURLOPT_FTP_USE_EPSV, true);

            //Set return unix parameter (newline) as vbcrlf
            easy.SetOpt(CURLoption.CURLOPT_CRLF, true);

            //Get folder list
            easy.SetOpt(CURLoption.CURLOPT_FTPLISTONLY, true);

            //Append FTP command
            //slist.Append("cwd /pub");
            //slist.Append("cwd /pub/incoming");
            //slist.Append("quit");
            //easy.SetOpt(CURLoption.CURLOPT_QUOTE, slist);

            //Execute FTP connection
            easy.Perform();

            //Cleanup slist content (FTP command)
            slist.FreeAll();

            //Cleanup curl easy handle
            easy.Cleanup();

            //Global cleanup curl
            Curl.GlobalCleanup();

            //Wait before closing console
            String wait = Console.ReadLine();
        }

        public static Int32 OnWriteData(Byte[] buf, Int32 size, Int32 nmemb,
            Object extraData)
        {
            Console.Write("Messages : " +
System.Text.Encoding.UTF8.GetString(buf));
            return size * nmemb;
        }

        public static void OnDebug(CURLINFOTYPE infoType, String msg, Object
extraData)
        {
            Console.WriteLine(msg);
        }

    }
}
Received on 2006-04-12