gpt4 book ai didi

c# - 将文件上传到 FTPS 服务器

转载 作者:太空宇宙 更新时间:2023-11-03 15:00:12 24 4
gpt4 key购买 nike

我正在尝试将文件上传到 FTP 服务器 (FTPS)。运行以下代码会产生异常:

The remote certificate is invalid according to the validation procedure.

代码:

static void Main(string[] args)
{
FTPFactory ftp = new FTPFactory();

ftp.setDebug(true);
ftp.setRemoteHost("ftps.host");
//Connect to SSL Port (5920)
ftp.setRemotePort(5920);
ftp.loginWithoutUser();

string cmd = "AUTH SSL";
ftp.sendCommand(cmd);

//Create SSL Stream
ftp.getSslStream();
ftp.setUseStream(true);
//Login FTP Secure
// ftp.setRemoteUser(Settings.Default.TargetFtpSecureUser);
ftp.setRemoteUser("user");
// ftp.setRemotePass(Settings.Default.TargetFtpSecurePass);
ftp.setRemotePass("pass");
ftp.login();

//Set ASCII Mode
ftp.setBinaryMode(false);


//Upload file

// Send Argument if you want
// cmd = "site arg1 arg2";
// ftp.sendCommand(cmd);

ftp.upload("", false);
ftp.uploadSecure(@"Filepath", false);

ftp.close();
}
catch (Exception e)
{
Console.WriteLine("Caught Error :" + e.Message);
}
}

这是 FTPFactory 类:

using System;
using System.Net.Sockets;

namespace FTP_DLL
{
public class FTPFactory
{
public FTPFactory();

public void chdir(string dirName);
public void close();
public Socket createDataSocket();
public void deleteRemoteFile(string fileName);
public void download(string remFileName);
public void download(string remFileName, bool resume);
public void download(string remFileName, string locFileName);
public void download(string remFileName, string locFileName, bool resume);
public string[] getFileList(string mask);
public long getFileSize(string fileName);
public string getRemoteHost();
public string getRemotePath();
public int getRemotePort();
public void getSslStream();
public void getSslStream(Socket Csocket);
public void login();
public void loginWithoutUser();
public void mkdir(string dirName);
public void renameRemoteFile(string oldFileName, string newFileName);
public void rmdir(string dirName);
public void sendCommand(string command);
public void setBinaryMode(bool mode);
public void setDebug(bool debug);
public void setRemoteHost(string remoteHost);
public void setRemotePass(string remotePass);
public void setRemotePath(string remotePath);
public void setRemotePort(int remotePort);
public void setRemoteUser(string remoteUser);
public void setUseStream(bool value);
public void upload(string fileName, bool resume);
public void uploadSecure(string fileName, bool resume);
}
}

最佳答案

我建议看一下 this article

听上去,问题是 FTP 服务器正在查看您的应用程序的证书,但不接受它。正如他们在文章中解释的那样,有一些插件允许您为您的应用程序获取/制作符合您的 FTP 服务器的证书。

关于c# - 将文件上传到 FTPS 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23394360/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com