我正在开发一个Android应用程序,该程序可以通过蓝牙从4个传感器收集一些数据,最后将数据发送到SFTP服务器。 我使用的是JSCh(ChannelSftp),在某些服务器上运行正常,但在我大学的服务器上应用程序崩溃。 我与IT官员进行了一次深度调试,我们发现,一旦SSH通道打开,一些后台流量就会到达服务器(例如:myIP --- otherIP ---数据包)。那时防火墙关闭了连接,导致应用程序崩溃。
是否有一种方法可以在短时间内阻止来自应用程序的后台流量?有人和我有同样的问题吗?
预先感谢
public class SftpClass extends AsyncTask <Object, Void, String> {
private Context context;
private long size;
private long fileSize;
public SftpClass (Context con){
context = con;
size = 0;
fileSize = -1;
}
@Override
protected String doInBackground(Object... params){
//Params: File file, String host, String port, String username, String password
File file = (File) params[0];
String host = (String) params[1];
String port = (String) params[2];
String username = (String) params[3];
String password = (String) params[4];
String path = (String) params[5];
int portnumber = Integer.valueOf(port);
fileSize = file.length();
String localFilePath = file.getAbsolutePath();
String fileName = localFilePath.substring(localFilePath.lastIndexOf("/") + 1);
String remoteFilePath = fileName;
JSch jsch = new JSch();
Session session = null;
try {
session = jsch.getSession(username, host, portnumber);
session.setConfig("StrictHostKeyChecking", "no");
session.setPassword(password);
session.connect();
Channel channel = session.openChannel("sftp");
channel.connect();
final ChannelSftp sftpChannel = (ChannelSftp) channel;
sftpChannel.put(localFilePath, path+remoteFilePath);
try
{
Thread.sleep(3000);
}
catch(InterruptedException ex)
{
Thread.currentThread().interrupt();
}
SftpATTRS attrs = null;
try {
attrs = sftpChannel.lstat(path+remoteFilePath);
} catch (SftpException e) {
e.printStackTrace();
}
if ( attrs != null){
size = attrs.getSize();
}
sftpChannel.exit();
session.disconnect();
} catch (JSchException e) {
e.printStackTrace();
} catch (SftpException e) {
e.printStackTrace();
}
return "";
}
@Override
protected void onPostExecute(String result) {
if (size == fileSize){
Toast.makeText(context, "File uploaded\n"+Long.toString(size)+"Bytes", Toast.LENGTH_SHORT).show();
}
}
}