android上传二进制文件大小,Android ftp4j - 上传成功后,远程文件大小与本地文件大小不匹配(Android ftp4j - remote file size doesn't mat...

Android ftp4j - 上传成功后,远程文件大小与本地文件大小不匹配(Android ftp4j - remote file size doesn't match local file size after upload success)

我在这里得到了一个奇怪的错误。 为了将文件上传到我的ftp服务器,我在我的Android应用程序中导入了ftp4j包。 问题是每当上传完成后上传的文件大小发生变化,我检查的文件内容也与原始内容不符。 另外我不认为这是由于网络问题意外造成的,因为我测试了我的代码三次并得到了相同的结果,原始文件大小为154266字节,每次上传完成后远程大小变为201673字节。

这是我的代码的一部分。

client = new FTPClient();

client.upload(file, new MyTransferListener(file));

public class MyTransferListener implements FTPDataTransferListener {

private File file;

private String filename;

public MyTransferListener(File file) {

this.file = file;

filename = file.getName();

}

...

@Override

public void completed() {

try {

file.delete();

} catch (Exception e) {}

}

...

}

I got a weird bug here. In order to upload file to my ftp server I imported ftp4j package in my android app. Problem is whenever the upload is complete the uploaded file size change, I checked the file content it does not match the original content as well. Also I don't think this is caused by internet problem accidentally, as I tested my code for three times and I got the same results, the original file size is 154266 in bytes and the remote size became 201673 bytes every time the upload completed.

Here is part of my code.

client = new FTPClient();

client.upload(file, new MyTransferListener(file));

public class MyTransferListener implements FTPDataTransferListener {

private File file;

private String filename;

public MyTransferListener(File file) {

this.file = file;

filename = file.getName();

}

...

@Override

public void completed() {

try {

file.delete();

} catch (Exception e) {}

}

...

}

原文:https://stackoverflow.com/questions/35044279

更新时间:2020-07-24 09:07

最满意答案

认为您正在以文本模式上传。 尝试先将客户端置于二进制传输模式。

Think you are uploading in text mode. Try to put your client in binary transfer mode first.

2016-01-27

相关问答

我终于找出了问题所在, 我已经为这个应用程序添加了一个日志过滤器,它将改变该日志记录过滤器中的请求。 删除了更改请求的部分。 现在工作正常。 I finally figured out what was the issue, I had put a logging filter to this application which would alter the request in that logging filter. Removed the part where the request is

...

莫希特, 使用Socket dtConnection; dtConnection.getInputStream(); ftp4j.FTPClient你将获得InputStream,使用该InputStream你可以读取第一行。 您可以在下面的示例中找到使用InputStream读取第一行的示例 BufferedReader bufferedReader = null; String firstLine = null; bufferedReader = new BufferedReader(new

...

可能的问题 FTP协议在客户端和服务器之间使用单独的控制和数据TCP连接。 在文件传输期间,数据连接正忙,但控制连接处于空闲状态。 根据您的日志,转移需要15分钟。 这意味着控制连接在这段时间内处于空闲状态。 某些防火墙或网络路由器可以在一段时间内断开连接而不进行任何活动。 看起来就是这种情况,因为readFTPReply尝试从控制连接读取并抛出“Read timed out” 。 如何调试 您可以通过Wireshark或tcpdump在客户端进行流量转储,并尝试找出控制连接断开的原因。 怎么修

...

有一种下载方法可供使用。 你可以使用client.download("myfile.txt", new java.io.File("d:/myfile.txt")); 这会将“myfile.txt”下载到“D:\ myfile.txt”。 对于Android,整个事情略有不同。 如果要将文件存储在已定义的文件夹中(例如sdcard上的示例),您可以像这样使用它: client.download("myfile.txt", new java.io.File("/sdcard/myfile.txt")

...

假设您可以在本地和远程端直接访问文件。 您可以在双方调用大小。 Net::FTP.open('ftp.example.com') do |ftp|

...

ftp.putbinaryfile('local.file', 'remote.file')

remote_size = ftp.size('remote_file')

local_size = File.size('local_file')

if remote_s

...

使用FTP_BINARY而不是FTP_ASCII 。 后者可能会在第一个NUL字节停止。 除此之外,现在没有充分的理由使用ascii模式,即使对于ascii文件也是如此。 唯一的情况是,如果你的cgi脚本包含一个在本地有windows linebreaks的shebang行,这很重要。 Use FTP_BINARY instead of FTP_ASCII. The latter might stop at the first NUL byte. Besides that, there is no

...

您的文件名包含通常需要转义的字符( ( , ) )。 你需要引用变量。 说: curl --upload-file "$ARCNAME" ftp://$WEBDAVUSER:$WEBDAVPASS@$WEBDAVURL

Your filename contains characters ((, )) that would typically need to be escaped. You need to quote the variable. Say: curl --upload-file "$

...

不,没有大小上传限制。 这是规范 ,这里是一个关于如何检查文件大小的相关问题,以便您可以添加限制。 值得指出的是,如果您希望将文件存储在服务器上,则可能会遇到文件上载限制/限制。 但是你应该能够配置它们。 即php / wordpress默认上传限制 Nope, there is no size upload limit. here is the spec and here is a related question on how to check the file size, so that y

...

认为您正在以文本模式上传。 尝试先将客户端置于二进制传输模式。 Think you are uploading in text mode. Try to put your client in binary transfer mode first.

这是我最后编写的代码 它仍然可以通过各种方式进行优化,因此可以进行任何性能,语义或重构编辑。 我不是专家。 代码说明 在var _maxFilsize您必须以字节为单位写入允许的最大文件大小。 Function Validate有一个参数oForm ,它需要一个HTML object ,通过它可以搜索输入字段。 将所有input元素存储在数组arrInputs 。 以变量inputType string形式存储arrInputs[i].type值 在if/else语句中将inputType的值与不

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值