- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 SimpleFTP.java 代码通过 FTP 上传图像。我收到标题中提到的错误并且无法上传图片。它只是将图像保存在数据库中,大小为 0KB。请帮我解决这个问题,因为我搜索了一整天但找不到正确的解决方案。
public class SimpleFTP {
/**
* Create an instance of SimpleFTP.
*/
public SimpleFTP() {
}
/**
* Connects to the default port of an FTP server and logs in as
* anonymous/anonymous.
*/
public synchronized void connect(String host) throws IOException {
connect(host, 21);
}
/**
* Connects to an FTP server and logs in as anonymous/anonymous.
*/
public synchronized void connect(String host, int port) throws IOException {
connect(host, port, "anonymous", "anonymous");
}
/**
* Connects to an FTP server and logs in with the supplied username
* and password.
*/
public synchronized void connect(String host, int port, String user, String pass) throws IOException {
if (socket != null) {
throw new IOException("SimpleFTP is already connected. Disconnect first.");
}
socket = new Socket(host, port);
reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
String response = readLine();
if (!response.startsWith("220 ")) {
throw new IOException("SimpleFTP received an unknown response when connecting to the FTP server: " + response);
}
sendLine("USER " + user);
response = readLine();
if (!response.startsWith("331 ")) {
throw new IOException("SimpleFTP received an unknown response after sending the user: " + response);
}
sendLine("PASS " + pass);
response = readLine();
if (!response.startsWith("230 ")) {
throw new IOException("SimpleFTP was unable to log in with the supplied password: " + response);
}
}
/**
* Disconnects from the FTP server.
*/
public synchronized void disconnect() throws IOException {
try {
sendLine("QUIT");
} finally {
socket = null;
}
}
/**
* Returns the working directory of the FTP server it is connected to.
*/
public synchronized String pwd() throws IOException {
sendLine("PWD");
String dir = null;
String response = readLine();
if (response.startsWith("257 ")) {
int firstQuote = response.indexOf('\"');
int secondQuote = response.indexOf('\"', firstQuote + 1);
if (secondQuote > 0) {
dir = response.substring(firstQuote + 1, secondQuote);
}
}
return dir;
}
/**
* Changes the working directory (like cd). Returns true if successful.
*/
public synchronized boolean cwd(String dir) throws IOException {
sendLine("CWD " + dir);
String response = readLine();
return (response.startsWith("250 "));
}
/**
* Sends a file to be stored on the FTP server.
* Returns true if the file transfer was successful.
* The file is sent in passive mode to avoid NAT or firewall problems
* at the client end.
*/
public synchronized boolean stor(File file) throws IOException {
if (file.isDirectory()) {
throw new IOException("SimpleFTP cannot upload a directory.");
}
String filename = file.getName();
return stor(new FileInputStream(file), filename);
}
/**
* Sends a file to be stored on the FTP server.
* Returns true if the file transfer was successful.
* The file is sent in passive mode to avoid NAT or firewall problems
* at the client end.
*/
public synchronized boolean stor(InputStream inputStream, String filename) throws IOException {
BufferedInputStream input = new BufferedInputStream(inputStream);
sendLine("PASV");
String response = readLine();//227
Log.e("RESPONSE ", response);
if (!response.startsWith("200 ") && !response.startsWith("227 ")) {
throw new IOException("SimpleFTP could not request passive mode: " + response);
}
String ip = null;
int port = -1;
int opening = response.indexOf('(');
int closing = response.indexOf(')', opening + 1);
if (closing > 0) {
String dataLink = response.substring(opening + 1, closing);
StringTokenizer tokenizer = new StringTokenizer(dataLink, ",");
try {
ip = tokenizer.nextToken() + "." + tokenizer.nextToken() + "." + tokenizer.nextToken() + "." + tokenizer.nextToken();
port = Integer.parseInt(tokenizer.nextToken()) * 256 + Integer.parseInt(tokenizer.nextToken());
//Log.e("FTP ",String.valueOf(port)+" P "+String.valueOf(port));
} catch (Exception e) {
throw new IOException("SimpleFTP received bad data link information: " + response);
}
}
sendLine("STOR " + filename);
Socket dataSocket = new Socket(ip, port);
response = readLine();
if (!response.startsWith("150 ")) {
throw new IOException("SimpleFTP was not allowed to send the file: " + response);
}
BufferedOutputStream output = new BufferedOutputStream(dataSocket.getOutputStream());
byte[] buffer = new byte[4096];
int bytesRead = 0;
while ((bytesRead = input.read(buffer)) != -1) {
output.write(buffer, 0, bytesRead);
}
output.flush();
output.close();
input.close();
response = readLine();
return response.startsWith("226 ");
}
/**
* Enter binary mode for sending binary files.
*/
public synchronized boolean bin() throws IOException {
sendLine("TYPE I");
String response = readLine();
return (response.startsWith("200 "));
}
/**
* Enter ASCII mode for sending text files. This is usually the default
* mode. Make sure you use binary mode if you are sending images or
* other binary data, as ASCII mode is likely to corrupt them.
*/
public synchronized boolean ascii() throws IOException {
sendLine("TYPE A");
String response = readLine();
return (response.startsWith("200 "));
}
/**
* Sends a raw command to the FTP server.
*/
private void sendLine(String line) throws IOException {
if (socket == null) {
throw new IOException("SimpleFTP is not connected.");
}
try {
writer.write(line + "\r\n");
writer.flush();
if (DEBUG) {
System.out.println("> " + line);
}
} catch (IOException e) {
socket = null;
throw e;
}
}
private String readLine() throws IOException {
String line = reader.readLine();
if (DEBUG) {
System.out.println("< " + line);
}
return line;
}
private Socket socket = null;
private BufferedReader reader = null;
private BufferedWriter writer = null;
private static boolean DEBUG = false;
}
最佳答案
我得到了答案。它的格式是
227 Entering Passive Mode (h1,h2,h3,h4,p1,p2) 其中 h1 到 h4 是格式为 h1:h2:h3:h4 的主机 ID,p1 -p2 是它阻塞的端口格式 p1*256+p2
关于java - 227进入被动模式(124,153,94,30,242,138),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19603593/
我是单元测试的新手。我已经对 Controller 类进行了单元测试,但从未测试过模态类。我正在为我的应用程序使用被动 View 模式。 我正在使用 Cpp 单元测试框架。 如有任何提示,我们将不胜感
我正在尝试为 RabbitMQ 的两个数据中心之间提供灾难恢复。在主 DC 出现故障之前,辅助数据中心处于被动状态。 队列联合是不合适的,因为在辅助 DC 中的使用者激活之前它不会移动消息。除非主 D
我正在使用斯坦福标记器来确定词性。但是,我想从文本中获取更多信息。是否有可能获得更多信息,例如句子的时态或是否处于主动/被动状态? 到目前为止,我使用的是非常基本的 PoS 标记方法: List> t
我有一个客户端,您不能使用主动 FTP 连接,因为它们受接口(interface)应用程序的限制。我遇到的问题是我的 Active 设置很好,但无法理解为什么我的被动 FTP 只会超时。 我已关注这篇
正如“构建您自己的 CAB”博文系列中提到的,当您采用被动 View 设计模式时,无法利用数据绑定(bind)。这对我来说并不像我想要的那样清楚。那么,你们中的任何一个人能否展示在监督 Control
我想做的是以下内容:一个服务,持续监听 gps(是的:JUST gps)位置更新而不主动请求它们 - 即这个应用程序不应该消耗额外的资源电池生命周期或 CPU 时间,直到其他应用程序请求/接收 GPS
我正在尝试实现 Passive View基于 swing 的 gui 系统。基本上我想保持我的 View 实现(实际包含 swing 代码的部分)最少,并在我的 Presenter 类中完成大部分工作
RFC 1006 TCP 连接中主动连接和被动连接有何区别? 最佳答案 这里有解释:https://www.rfc-editor.org/rfc/rfc793 A passive OPEN reque
在 MarkLogic 7 中,副本是主动-主动还是主动-被动? 最佳答案 您是在询问本地磁盘故障转移(又名林复制)、数据库复制还是灵活复制? 事实上,这三个都是为主动-被动使用而设计的:换句话说,单
我们计划使用 kubernetes 在容器平台中设置高度可用的 Jenkins。我们正在考虑设置一个事件主机和另一个处于待机模式的主机。Jenkins 数据量将存储在两个主容器之间共享的全局存储中。
我已在多个网站( http://blogs.thesitedoctor.co.uk/tim/Trackback.aspx?guid=e81a4682-0851-490b-a3d2-adf254a701
我目前正在学习 MVP 设计模式,并且对简单逻辑应该放在哪里有疑问。 我的印象是所有业务逻辑都应该进入模型,这是否包括简单的方法,例如: public int Add(int a, int b){
我研究 MVP 模式已有一段时间,并设法创建了一些简单的 MVP 兼容应用程序。 我现在正尝试将该模式应用到一个更复杂的应用程序中,但我对这样做的最佳方式存疑。 我的应用程序只有一个 WinForm,
View 是否应该在其接口(interface)中没有任何特定于事件的内容并调用演示者普通方法来处理事件并且没有任何官方的 EventHandlers?比如 // ASPX protected voi
我有一个应用程序,需要在负载均衡器后面以主动-被动模式设置,以便所有连接都应转到主动实例。如果主动实例出现故障,它应该从被动实例启动 session 。 我收集到的唯一信息是我们只能在负载均衡器后面设
我已经使用被动 View 模式实现了一个 MVP 三元组——即 View 只包含简单的 getter 和 setter。但是我在分离 View 数据和模型数据时遇到了问题。特别是在处理 View 状态
我一直在用我认为的 Passive MVP 实现我的 android 应用。 例如,在我的 View 类中,我有一个 ListView。 查看 ListView userListView; 当一个项目
我正在尝试通过我正在构建的迁移向导中的 shell 命令执行静默安装。 msiexec /i E:\mysql-installer-community-5.6.16.0.msi /passive 虽然
我在 Passive View 上找到了 M. Fowler 的文章图案。我想在我的申请中应用它。我将 Swing 用于 UI。我花了几个小时搜索如何实现它的教程或示例,但没有找到太多有用的东西。有人
我正在用 C# 开发 WinForms 应用程序。我在 GUI 编程方面的经验有限,而且我必须即时学习很多东西。话虽这么说,这就是我正在 build 的。 查看一般 GUI 查看以下链接: GUI h
我是一名优秀的程序员,十分优秀!