在C#中使用CURL ftp在windows操作系统中上传文件。
我必须使用卷曲FTP上传FTP位置上的数据。但我对CURL命令知之甚少。我在网上搜索了很多,但没有找到任何C#的工作示例。我必须在C#中使用CURL命令创建一个应用程序,该命令可以在FTP上上载文件/文件夹 有人能给我提供一些示例或有用的链接吗?您可以像前面提到的那样在Powershell中使用。您可以在C#中使用此代码在C#中使用CURL ftp在windows操作系统中上传文件。,c#,curl,ftp,C#,Curl,Ftp,我必须使用卷曲FTP上传FTP位置上的数据。但我对CURL命令知之甚少。我在网上搜索了很多,但没有找到任何C#的工作示例。我必须在C#中使用CURL命令创建一个应用程序,该命令可以在FTP上上载文件/文件夹 有人能给我提供一些示例或有用的链接吗?您可以像前面提到的那样在Powershell中使用。您可以在C#中使用此代码 谢谢.Net为此内置了类,不需要curl:例如,是的,但是curl FTP有一些额外的功能,比如它不需要用户交互。。。。客户也建议使用CURL-FTP,这就是为什么我必须使用C
谢谢.Net为此内置了类,不需要curl:例如,是的,但是curl FTP有一些额外的功能,比如它不需要用户交互。。。。客户也建议使用CURL-FTP,这就是为什么我必须使用CURL-FTP的原因。当从代码调用时,任何FTP库都不可能需要用户交互
using System;
using System.Collections.Generic;
using SeasideResearch.LibCurlNet;
namespace libcurlFtpsExample
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("libcurlFtpsExample...");
const string url = "ftp://user:thepassword@ftp.somesite.com/dir/";
try
{
Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);
Easy easy = new Easy();
if (easy != null)
{
easy.SetOpt(CURLoption.CURLOPT_URL, url);
easy.SetOpt(CURLoption.CURLOPT_SSL_VERIFYPEER, false);
easy.SetOpt(CURLoption.CURLOPT_SSL_VERIFYHOST, false);
easy.SetOpt(CURLoption.CURLOPT_FTP_SSL, CURLftpSSL.CURLFTPSSL_TRY);
// For debugging will print headers to console.
Easy.HeaderFunction hf = new Easy.HeaderFunction(OnHeaderData);
easy.SetOpt(CURLoption.CURLOPT_HEADERFUNCTION, hf);
// For debugging will print received data to console.
Easy.DebugFunction df = new Easy.DebugFunction(OnDebug);
easy.SetOpt(CURLoption.CURLOPT_DEBUGFUNCTION, df);
easy.SetOpt(CURLoption.CURLOPT_VERBOSE, true);
// List directory only
easy.SetOpt(CURLoption.CURLOPT_FTPLISTONLY, true);
CURLcode code = easy.Perform();
if (code != CURLcode.CURLE_OK)
{
Console.WriteLine("Request failed!");
}
easy.Cleanup();
}
else
{
Console.WriteLine("Failed to get Easy libcurl handle!");
}
}
catch (Exception exp)
{
Console.WriteLine(exp);
}
finally
{
Curl.GlobalCleanup();
}
}
public static void OnDebug(CURLINFOTYPE infoType, String msg, Object extraData)
{
// print out received data only
if (infoType == CURLINFOTYPE.CURLINFO_DATA_IN)
Console.WriteLine(msg);
}
public static Int32 OnHeaderData(Byte[] buf, Int32 size, Int32 nmemb, Object extraData)
{
Console.Write(System.Text.Encoding.UTF8.GetString(buf));
return size * nmemb;
}
}
}