我正在尝试构建一个 Android 应用程序来使用 FTP 执行上传速度测试,但是使用以下代码,上传速度不会超过 1 Mbps。在同一设备上使用 FTP 客户端时,我可以获得 15 Mbps 的上传速度。有人可以帮我解决这个问题吗?
public class MultiUL extends Thread{
private String id="hhhhh0001";
private int bufferSize=32768;
public void run() {
FTPClient ftp = new FTPClient();
try {
ftp.connect(MPSharkVar.Server,21); // Using port no=21
ftp.login(MPSharkVar.FTPUser, MPSharkVar.FTPPwd);
ftp.setFileType(FTP.BINARY_FILE_TYPE);
ftp.enterLocalPassiveMode();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
uploadWork(ftp, id);
try {
ftp.disconnect();
}
catch (Exception ex)
{
}
}
private void uploadWork(FTPClient ftp, String id) {
byte[] buffer = new byte[bufferSize];
for (int i = 0; i < bufferSize; i++) {
buffer[i] = 'F';
}
OutputStream os = null;
BufferedOutputStream bos = null;
long start = System.currentTimeMillis();
long end = start;
try {
ftp.changeWorkingDirectory("/upload");
os = ftp.storeFileStream(id);
bos = new BufferedOutputStream(os);
start = System.currentTimeMillis();
end = start;
while (((end - start) <= MPSharkVar.TestDur)) {
bos.write(buffer, 0, buffer.length);
end = System.currentTimeMillis();
}
} catch (Exception ex) {
end = System.currentTimeMillis();
} finally {
try {
bos.flush();
bos.close();
os.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}