CMD_API_FILE_MANAGER upload file error ,how fixed

bestseller

New member
Joined
Jul 14, 2022
Messages
2
error=1&text=An Error Occurred&details=No files have been selected for upload

ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);
string url = "https://" + ftpIp + ":2222/CMD_API_FILE_MANAGER?path="+path+"&action=upload";
using (HttpClient client = new HttpClient())
{

// Set the authentication data
var byteArray = Encoding.ASCII.GetBytes($"{UserName}:{Password}");
client.DefaultRequestHeaders.Authorization =
new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));

byte[] nowBytes = System.Text.Encoding.UTF8.GetBytes(DateTime.Now.ToString());


// Create the request content with multipart/form-data format
var content = new MultipartFormDataContent();
content.Headers.Add("X-DirectAdmin-File-Upload", "yes");
content.Headers.Add("X-DirectAdmin-File-Name", Path.GetFileName(filePath));
var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
var fileContent = new StreamContent(fileStream);
fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
{
Name = "file1",
FileName = Path.GetFileName(filePath),
};
fileContent.Headers.ContentType = new MediaTypeHeaderValue("application/x-zip-compressed");

content.Add(fileContent, "file1", Path.GetFileName(filePath));

HttpResponseMessage response = client.PostAsync(url, content).Result;
response.EnsureSuccessStatusCode();

Console.WriteLine(response.Content.ReadAsStringAsync().Result);

}
 
Back
Top