在C#中,可以使用FTP协议来将数组直接保存到FTP服务器。可以使用System.Net.WebClient
类来实现这一功能。以下是一个示例代码:
using System;
using System.IO;
using System.Net;
class Program
{
static void Main()
{
string ftpServer = "ftp://ftp.example.com/";
string username = "username";
string password = "password";
string fileName = "array.txt";
byte[] array = { 1, 2, 3, 4, 5 };
UploadArrayToFtpServer(ftpServer, username, password, fileName, array);
}
static void UploadArrayToFtpServer(string ftpServer, string username, string password, string fileName, byte[] array)
{
string ftpPath = $"{ftpServer}/{fileName}";
using (WebClient client = new WebClient())
{
client.Credentials = new NetworkCredential(username, password);
client.UploadData(ftpPath, "STOR", array);
}
Console.WriteL