在使用 .Net6 的 C# 中,我们可以使用 -object 与 FTP 服务器交互FtpWebRequest
。这效果很好。但是我们应该如何创建这个对象呢?目前我们使用WebRequest.Create()
并且微软说我们应该这样做。
但这个功能现在已经过时了。因此,当Create
-function 已过时但FtpWebRequest
-type 未过时时,FtpWebRequest
在不使用过时函数的情况下创建 -object 的正确且推荐的方法是什么?
批处理脚本如下:
>>ftp.txt open ftp.site.com
>>ftp.txt username
>>ftp.txt password
>>ftp.txt directoryname
>>ftp.txt quit
ftp -s ftp.txt
Run Code Online (Sandbox Code Playgroud)
如何删除文件夹'directoryname'中的所有文件?
我有一个具有完全访问权限的Web托管服务器.我是一名Web开发人员,所以FTP是我每天用于更新网站的.我正在使用FTP客户端,在设置服务器信息后,当我尝试连接时,我收到了一个错误,而FTP客户端已向服务器发送"MLSD"commant.
这是客户端LOG:
Status: Resolving address of si****.co (edited)
Status: Connecting to 74.208.***.***:21... (edited)
Status: Connection established, waiting for welcome message...
Response: 220 ProFTPD 1.3.3e Server (ProFTPD) [74.208.***.***] (edited)
Command: USER si***** (edited)
Response: 331 Password required for si*****
Command: PASS ********
Response: 230 User si***** logged in
Command: SYST
Response: 215 UNIX Type: L8
Command: FEAT
Response: 211-Features:
Response: MDTM
Response: MFMT
Response: TVFS
Response: UTF8
Response: MFF modify;UNIX.group;UNIX.mode;
Response: MLST modify*;perm*;size*;type*;unique*;UNIX.group*;UNIX.mode*;UNIX.owner*;
Response: LANG en-US*;fr-FR;it-IT;ja-JP;ko-KR;ru-RU;zh-CN;zh-TW;bg-BG
Response: REST STREAM
Response: SIZE …
Run Code Online (Sandbox Code Playgroud) 我有一些问题与我们运行过夜的dos文件将一些文件发送到另一家公司的ftp服务器,另一家公司检查了他们的日志,我们正在连接并且能够登录但是没有文件被转移.我想知道使用put命令和send命令之间是否存在差异.新旧系统不支持其中一种吗?
当我尝试通过firefox或IE连接到我的ftp服务器时,收到以下消息:
530 Login authentication failed
Run Code Online (Sandbox Code Playgroud)
为什么我收到此消息?用户名和密码正确。
登录到ftp服务器之前,他们在本地计算机上需要执行哪些要求?
我曾经ftp://example.com
登录。
我正在编写一个连接到 FTP 服务器以读取一些文件的 Rest 服务,然后对读取的数据进行一些操作以服务于服务请求。我正在使用 Apache 公共资源FTPClient
。
作为临时解决方案,我正在创建一个FTPClient
对象 - 然后连接它 - 然后使用凭据登录 -FTPClient
在我的数据访问层中的一个方法(客户端是该方法的本地 - 这样做不是线程安全的),然后在退出方法之前(即......读取文件后)断开它。问题是,FTPClient
登录需要 3-7 秒,这是非常高的。所以我正在考虑实现一个FTPClientPool
可以在数据访问方法中提供一个已经准备好的客户端。
是否已经存在任何这样的 ClientPools?
如果是,那么我应该选择哪一种?
如果不是,实现的难点是一旦创建和连接, apache FTPClient 存活多久?无限时间??(我的意思是 FTPClient 的默认保持活动时间是多少 - 客户端断开连接后的空闲时间 - 因为我在 java 文档中看到了各种时间。:()接下来的问题是你如何让它始终保持活动状态??(可能会在一个单独的线程中定期发送 NOOPS ??)关于我应该如何前进的任何帮助都非常有帮助。
感谢和问候
java multithreading connection-pooling ftp-client apache-commons-net
我试图列出ftp服务器中特定目录下的所有文件.
FTPFile[] subFiles = ftpClient.listFiles("directory");
Run Code Online (Sandbox Code Playgroud)
虽然目录是有效的,但是在调用listFiles时代码卡住了,可能是原因.?此外,我想提一下,访问同一个FTP服务器的单独netbeans项目使用相同的代码工作正常,但是maven项目遇到了问题.请帮忙.
我正在从Apache库(commons.net ver 3.2)的帮助下从服务器下载ftp文件.下载很好,我收到了我需要的所有文件,并将它们保存在一个文件夹中.我遇到的问题是超时,因为当我下载时连接中断时我需要一条错误消息,告诉我连接已经丢失,但我发现这样做很困难,我搜索了无数的论坛,包括这个一个,我已经尝试了很多方法来解决这个问题,但还没有人有结果!我的代码如下:
public void doSomething(String ip, int port, String user, String pass, String server, String remotePath, String localPath) {
int tenseconds = 10 * 1000;
int thirtyseconds = 30 * 3000;
Socket s4 = new Socket();
java.net.InetSocketAddress adr = new java.net.InetSocketAddress("213.0.17.234", 21);
s4.connect(adr, thirtyseconds);
FTPClient client = new FTPClient();
org.apache.commons.vfs2.FileSystemOptions fileSystemOptions = null;
String key = FtpFileSystemConfigBuilder.getInstance().getEntryParser(fileSystemOptions);
try {
client.setConnectTimeout(tenseconds);
client.setDefaultTimeout(thirtyseconds);
client.connect(ip, port);
client.setSoTimeout(thirtyseconds);
int reply = client.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
throw new FileSystemException("vfs.provider.ftp/connect-rejected.error");
}
client.enterLocalPassiveMode();
boolean login = …
Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个FTP客户端和服务器,它允许我通过匿名FTP将文件从客户端发送到服务器.但是,我一直在努力550 Permission Denied
.我可以做其他事情,比如从服务器下载文件,或者获取目录中的文件列表,但每当我尝试下载时,它都会说550 Permission Denied
.无论我是登录还是使用匿名FTP,结果都是一样的.
我没有看到我的代码有任何问题,但我尝试在不同的网络和计算机上运行它具有相同的结果.我看不到代码有问题,还是我必须对路由器/防火墙做些什么?
我用Java编写客户端和服务器并运行Windows.我正在使用的库是Apache Commons FTP Client
和Apache FTP Server
.
这是客户.注释掉的代码用于上载和获取目录中的文件列表.
import org.apache.commons.net.ftp.*;
import java.io.*;
import java.net.*;
public class Client
{
public Client()
{
// Do nothing
}
public void transferFile(String ipAddress)
{
// For uploading
FileInputStream file = null;
// For downloading
// FileOutputStream file = null;
try
{
InetAddress address = InetAddress.getByName(ipAddress);
FTPClient ftpClient = new FTPClient();
ftpClient.connect(address, 5000);
ftpClient.login("anonymous", "");
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
ftpClient.enterLocalPassiveMode();
// For uploading
file = …
Run Code Online (Sandbox Code Playgroud) 我正在使用FTPClient针对 FTP 服务器使用Testcontainers
.
可重现的代码示例如下:
import org.apache.commons.net.PrintCommandListener;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.images.builder.ImageFromDockerfile;
import org.testcontainers.junit.jupiter.Testcontainers;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import static org.assertj.core.api.Assertions.assertThat;
@Testcontainers
class FtpUtilsTest {
private static final int PORT = 21;
private static final String USER = "user";
private static final String PASSWORD = "password";
private static final int FTP_TIMEOUT_IN_MILLISECONDS = 1000 * 60;
private static final GenericContainer ftp = new …
Run Code Online (Sandbox Code Playgroud) ftp-client ×10
ftp ×8
java ×5
.net-6.0 ×1
batch-file ×1
c# ×1
connection ×1
ftp-server ×1
ftplib ×1
ftps ×1