我的帖子标题几乎说明了一切:如何使用.NET使用FTP over SSL从FTP服务器下载文件?我已经阅读了一些内容,并且有几个第三方组件需要购买以完成此功能.
这笔交易,这是一个非常specefic需求,并不会增长太多,因此,如果下载使用基于SSL的FTP FTP服务器的文件可以使用.NET Framework(即System.Net命名空间或东西)来完成,然后那将是最好的.我不需要一吨的功能,但如果针对一个安全的FTP服务器由于某种原因编码是一场噩梦或通过.NET Framework BCL不可行的,这将是很好的知道,作为一个第三方.DLL可能是最好的.
谢谢!
我想将文件上传到FTPS和SFTP.我的代码目前正在使用FtpWebRequest对象上传到FTP.我应该使用哪些更改或类来上传到FTP,FTPS和SFTP服务器?
更新中...
抱歉实时调试.我整天都陷入困境,我想写出来让我更接近研究它......
我注意到我正在使用setUseEPSVwithIPv4(true)发送一个
EPSV
229 Entering Passive Mode (|||62110|)
Run Code Online (Sandbox Code Playgroud)
删除它让我更进一步,现在我得到了
Total Bytes To Send: 1033
PASV
227 Entering Passive Mode (xxx,xxx,xxx,42,242,189)
STOR /Inbound/Encrypted/TEST.pgp
File Transfer Failed at: 2013-11-21 18:33:07.846
Error Occurred Transmitting File to Remote System, aborting...
Host attempting data connection xxx.xxx.xxx.42 is not same as server xxx.xxx.xxx.67
java.io.IOException: Host attempting data connection xxx.xxx.92.42 is not same as server xxx.xxx.xxx.67
at org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:912)
at org.apache.commons.net.ftp.FTPSClient._openDataConnection_(FTPSClient.java:600)
at org.apache.commons.net.ftp.FTPClient._storeFile(FTPClient.java:633)
at org.apache.commons.net.ftp.FTPClient.__storeFile(FTPClient.java:624)150 Opening ASCII mode SSL data connection for /Inbound/Encrypted/TCONW.TEST.IN.pgp.
at org.apache.commons.net.ftp.FTPClient.storeFile(FTPClient.java:1976)
at mycode.FTPConnection.sendFile(FTPConnection.java:667) …Run Code Online (Sandbox Code Playgroud) 我设置了 FTP 服务器(基于 ubuntu\vsftpd)。
我正在从互联网连接这个 ftp 服务器,所以我在服务器中激活了 SSL 安全功能。
为了检查一切是否正常,我使用 FileZiLla 进行了测试 -> 它正在运行。日志(来自 FileZilla):
Status: Connecting to ****:21...
Status: Connection established, waiting for welcome message...
Response: 220 (vsFTPd 3.0.2)
Command: AUTH TLS
Response: 234 Proceed with negotiation.
Status: Initializing TLS...
Status: Verifying certificate...
Command: USER ****
Status: TLS/SSL connection established.
Response: 331 Please specify the password.
Command: PASS ********
Response: 230 Login successful.
Command: SYST
Response: 215 UNIX Type: L8
Command: FEAT
Response: 211-Features:
Response: AUTH SSL
Response: AUTH …Run Code Online (Sandbox Code Playgroud) 我正在尝试访问我在ftps服务器中创建的路径中的文件夹,但它没有返回任何内容,它正在连接但不返回任何内容,如果我将服务器配置更改为ftp就可以了.我正在使用FileZilla Server,其配置在上面.
SSL/TLS
标记为true在SSL/TLS设置上启用FTP over SSL/TLS支持(FTPS)和允许显式FTP over TLS
我的用户配置是:
在FireZilla Server的用户配置常规中,平面"强制SSL用于用户登录".
关于连接的服务器日志正在收到消息,我不知道它是否有帮助:
227进入被动模式
LIST
需要521 PROT P.
PASV
227进入被动模式
NLST
需要521 PROT P.
放弃
我的连接示例类是上面的每个权限:
公共类FTPClientExample2 {
public static void main(String[] args)
{
String server = "myip";
int port = 2121;
String user = "joao";
String pass = "1234";
boolean error = false;
FTPSClient ftp = null;
try
{
ftp = new FTPSClient("SSL");
ftp.setAuthValue("SSL");
ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
int reply;
ftp.connect(server, port);
System.out.println("Connected to ftp.wpmikz.com.cn");
System.out.print(ftp.getReplyString());
// After connection attempt, you …Run Code Online (Sandbox Code Playgroud) 我使用带有 Java 8 的 Apache Commons Net (v3.5) 连接到远程 FTPS 站点(即在 Internet 上)。我可以在我的 Windows 10 机器上轻松连接 FileZilla 客户端,但我的 Java 程序无法完成相同的步骤。我在谷歌上搜索了高低,但找不到根本原因。以下是我已经确认的事情:
以下是代码,非常感谢您的任何想法:
import java.io.IOException;
import java.io.PrintWriter;
import org.apache.commons.net.PrintCommandListener;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;
import org.apache.commons.net.ftp.FTPSClient;
public class testProgram {
public static void main(String[] args) …Run Code Online (Sandbox Code Playgroud)