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: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66:
| using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using SeasideResearch.LibCurlNet;
namespace FTPUpload { class Program { static void Main(string[] args) { try { Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL); FileStream fs = new FileStream(args[0], FileMode.Open, FileAccess.Read, FileShare.Read); Easy easy = new Easy(); Easy.ReadFunction rf = new Easy.ReadFunction(OnReadData); easy.SetOpt(CURLoption.CURLOPT_READFUNCTION, rf); easy.SetOpt(CURLoption.CURLOPT_READDATA, fs); 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, args[1]); easy.SetOpt(CURLoption.CURLOPT_USERPWD, args[2] + ":" + args[3]); easy.SetOpt(CURLoption.CURLOPT_UPLOAD, true); easy.SetOpt(CURLoption.CURLOPT_INFILESIZE, fs.Length); easy.Perform(); easy.Cleanup(); fs.Close(); Curl.GlobalCleanup(); } catch (Exception ex) { Console.WriteLine(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) { Console.WriteLine(msg); }
public static Int32 OnProgress(Object extraData, Double dlTotal, Double dlNow, Double ulTotal, Double ulNow) { Console.WriteLine("Progress: {0} {1} {2} {3}", dlTotal, dlNow, ulTotal, ulNow); return 0; } } } |