I am trying in retrieving and writing signal from thirty-part machine (EEG headset) into file.csv through bluetooth. Now, i connect successfully with headset but while recording signal i met a fatal signal that i had no idea about.
Here is the code i possiply think might be the problem:
IEE_DataChannel_t[] Channel_list;
String[] Name_Channel = {"AF3","T7","Pz","T8","AF4"};
and the function to retrieve data
case 2:
if(bp_writer == null) return;
for(int i=0; i < Channel_list.length; i++)
{
SWIGTYPE_p_double ptheta = edkJava.new_double_p();
SWIGTYPE_p_double palpha = edkJava.new_double_p();
SWIGTYPE_p_double plow_beta = edkJava.new_double_p();
SWIGTYPE_p_double phigh_beta = edkJava.new_double_p();
SWIGTYPE_p_double pgamma = edkJava.new_double_p();
int result = -1;
result = edkJava.IEE_GetAverageBandPowers(userId, Channel_list[i], ptheta, palpha, plow_beta, phigh_beta, pgamma);
if(result == edkJava.EDK_OK){
Log.e("FFT", "GetAverageBandPowers");
try {
bp_writer.write(Name_Channel[i] + ",");
addData(edkJava.double_p_value(ptheta));
addData(edkJava.double_p_value(palpha));
addData(edkJava.double_p_value(plow_beta));
addData(edkJava.double_p_value(phigh_beta));
addData(edkJava.double_p_value(pgamma));
bp_writer.newLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
edkJava.delete_double_p(ptheta);
edkJava.delete_double_p(palpha);
edkJava.delete_double_p(plow_beta);
edkJava.delete_double_p(phigh_beta);
edkJava.delete_double_p(pgamma);
}
break;
}
}
};
there is the function for add data and set the file.csv:
private void setDataFile() {
try {
String eeg_header = "Channel , Theta ,Alpha ,Low beta ,High beta , Gamma ";
File root = Environment.getExternalStorageDirectory();
String file_path = root.getAbsolutePath()+ "/FFTSample/";
File folder=new File(file_path);
if(!folder.exists())
{
folder.mkdirs();
}
bp_writer = new BufferedWriter(new FileWriter(file_path+"bandpowerValue.csv"));
bp_writer.write(eeg_header);
bp_writer.newLine();
} catch (Exception e) {
Log.e("","Exception"+ e.getMessage());
}
}
public void addData(double data) {
if (bp_writer == null) {
return;
}
String input = "";
input += (String.valueOf(data) + ",");
try {
bp_writer.write(input);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
It added user successfully, but when started recording, i met
A/libc: Invalid address 0xda9739b8 passed to free: value not allocated
A/libc: Invalid address 0xda973068 passed to free: value not allocated
A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 3969 (motiv.fftsample)
A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 3938 (motiv.fftsample)
I/libc: Another thread contacted debuggerd first; not contacting debuggerd.
So, how do i track errors, i am just a beginner on building app. Thanks
Related
first of all changing volume is working but i got some problems while changing the volume so 1) after changing the volume like setting it to 0 (no volume) you still hearing parts of the song in the default value of the volume 2)after song changed the volume getting back to the default value of the volume
public static void setVolume(double value) {
System.out.println();
int CHANGE_VOLUME = 7;
midivol =(value);
try {
if (synthesizer.getDefaultSoundbank() == null) {
System.out.println(444);
ShortMessage volumeMessage = new ShortMessage();
for (int i = 0; i < 16; i++) {
volumeMessage.setMessage(ShortMessage.CONTROL_CHANGE, i, CHANGE_VOLUME,(int)(value * 127.0));
volumeMessage.setMessage(ShortMessage.CONTROL_CHANGE, i, 39, (int)(value * 127.0));
MidiSystem.getReceiver().send(volumeMessage, -1);
}
} else {
MidiChannel[] channels = synthesizer.getChannels();
for( int c = 0; c < channels.length; c++ ) {
if(channels[c] != null) channels[c].controlChange( 7, (int)( value*127.0) );
}
}
music.setSequence(sequence);
} catch (Exception e) {
e.printStackTrace();
}
}
playing midi:
private void playMidi(String location) {
double gain =Slider.musicvolume;
music = null;
//synthesizer = null;
sequence = null;
File midiFile = new File(location);
try {
sequence = MidiSystem.getSequence(midiFile);
music = MidiSystem.getSequencer(false);
music.open();
music.setSequence(sequence);
} catch (Exception e) {
System.err.println("Problem loading MIDI file.");
e.printStackTrace();
return;
}
if (music instanceof Synthesizer) {
synthesizer = (Synthesizer) music;
} else {
try {
synthesizer = MidiSystem.getSynthesizer();
synthesizer.open();
if (synthesizer.getDefaultSoundbank() == null) {
music.getTransmitter().setReceiver(MidiSystem.getReceiver());
} else {
music.getTransmitter().setReceiver(synthesizer.getReceiver());
}
} catch (Exception e) {
e.printStackTrace();
return;
}
}
MidiChannel[] channels = synthesizer.getChannels();
for (int i = 0; i < channels.length; i++) {
channels[i].controlChange(7, (int) (gain * 127.0));
}
try {
music.setSequence(sequence);
} catch (InvalidMidiDataException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
music.setLoopCount(Sequencer.LOOP_CONTINUOUSLY);
music.start();
}
volumeMessage.setMessage(ShortMessage.CONTROL_CHANGE, i, CHANGE_VOLUME,(int)(value * 127.0));
volumeMessage.setMessage(ShortMessage.CONTROL_CHANGE, i, 39, (int)(value * 127.0));
MidiSystem.getReceiver().send(volumeMessage, -1);
This code sends one message. The contents of that message are the values set by the second setMessage call, so the volume MSB is not changed at all.
(And this is the wrong way of computing the LSB.)
Controller 7 is indeed for volume, but there is no exact standard for how the values are to be interpreted. Apparently, your synthesizer does not mute itself when it receives a volume of zero.
Many MIDI files do their own changes to controller 7. If your synthesizer supports Master Volume, you should send that instead.
So, I'm trying to create a function (If not pretty) IRC client using no libraries, written in Java. I've gotten almost everything working, the only problem is that I'm currently getting user input using System.in. And if someone else in the channel sends a message while I'm in the middle of typing, it cuts off what I currently have, and I need to guess where I am in the string. I want to know if there's a way to separate user input from the output of the program, so that this doesn't happen. This is the code in question:
new Thread(() -> {
while(connected[0]) {
String output = sc.nextLine();
if(!output.startsWith("~") && !output.startsWith("/")) {
try {
writeToSocket("PRIVMSG " + focused[0] + " " + output);
} catch (IOException e) {
e.printStackTrace();
}
}
if(output.substring(1).toLowerCase().startsWith("quit")) {
String[] split = output.substring(5).split(" ");
StringBuilder sb = new StringBuilder();
for (int i = 0; i < split.length; i++) {
if(i == 0) {
sb.append(split[i]);
}
sb.append(" ").append(split[i]);
}
try {
writeToSocket("QUIT " + sb.toString());
connected[0] = false;
} catch (IOException e) {
e.printStackTrace();
}
}else if(output.substring(1).toLowerCase().startsWith("focus")) {
String get = output.substring(7);
if(!channels.contains(get)) {
print("Not connected to channel");
}else {
try {
writeToSocket("PART " + focused[0]);
writeToSocket("JOIN " + get);
} catch (IOException e) {
e.printStackTrace();
}
focused[0] = get;
}
}else if(output.substring(1).toLowerCase().startsWith("join")) {
String get = output.substring(6);
channels.add(get);
}
if(output.startsWith("/") && output.substring(1).toLowerCase().startsWith("msg")) {
String[] split = output.substring(5).split(" ");
String username = split[0];
StringBuilder msg = new StringBuilder();
for(int i = 1; i < split.length; i++) {
if(i == 1) {
msg.append(split[i]);
continue;
}
msg.append(" ").append(split[i]);
}
try {
writeToSocket("PRIVMSG " + username + " " + msg.toString());
} catch (IOException e) {
e.printStackTrace();
}
}
}
}).start();
I wrote an Android app that plays multi-track audio files and it works completely in the simulator. On the device, it plays for a few seconds and then starts skipping and popping every few seconds. If I continuously tap the screen in the dead space of the app, the skipping doesn't occur and then recurs about 5 seconds after screen tapping ceases. I presume that this has something to do with thread priority, but I log the thread priority in the play loop and it never changes.
I'm hoping that somebody can tell me either:
a hack where I can simulate a screen tap every second so that I can run a beta test without the app skipping
explain a way to debug activity/thread/etc priority when it seems that my thread priority isn't changing when it seems like it is.
Here is how the player code is executed:
private class DecodeOperation extends AsyncTask<Void, Void, Void> {
#Override
protected Void doInBackground(Void... values) {
AudioTrackPlayer.this.decodeLoop();
return null;
}
#Override
protected void onPreExecute() {
}
#Override
protected void onProgressUpdate(Void... values) {
}
}
Here is the relevant player code:
private void decodeLoop()
{
ByteBuffer[] codecInputBuffers;
ByteBuffer[] codecOutputBuffers;
// extractor gets information about the stream
extractor = new MediaExtractor();
try {
extractor.setDataSource(this.mUrlString);
} catch (Exception e) {
mDelegateHandler.onRadioPlayerError(AudioTrackPlayer.this);
return;
}
MediaFormat format = extractor.getTrackFormat(0);
String mime = format.getString(MediaFormat.KEY_MIME);
// the actual decoder
codec = MediaCodec.createDecoderByType(mime);
codec.configure(format, null /* surface */, null /* crypto */, 0 /* flags */);
codec.start();
codecInputBuffers = codec.getInputBuffers();
codecOutputBuffers = codec.getOutputBuffers();
// get the sample rate to configure AudioTrack
int sampleRate = format.getInteger(MediaFormat.KEY_SAMPLE_RATE);
Log.i(LOG_TAG,"mime "+mime);
Log.i(LOG_TAG,"sampleRate "+sampleRate);
// create our AudioTrack instance
audioTrack = new AudioTrack(
AudioManager.STREAM_MUSIC,
sampleRate,
AudioFormat.CHANNEL_OUT_5POINT1,
AudioFormat.ENCODING_PCM_16BIT,
AudioTrack.getMinBufferSize (
sampleRate,
AudioFormat.CHANNEL_OUT_5POINT1,
AudioFormat.ENCODING_PCM_16BIT
),
AudioTrack.MODE_STREAM
);
// start playing, we will feed you later
audioTrack.play();
extractor.selectTrack(0);
// start decoding
final long kTimeOutUs = 10000;
MediaCodec.BufferInfo info = new MediaCodec.BufferInfo();
boolean sawInputEOS = false;
boolean sawOutputEOS = false;
int noOutputCounter = 0;
int noOutputCounterLimit = 50;
while (!sawOutputEOS && noOutputCounter < noOutputCounterLimit && !doStop) {
//Log.i(LOG_TAG, "loop ");
noOutputCounter++;
if (!sawInputEOS) {
inputBufIndex = codec.dequeueInputBuffer(kTimeOutUs);
bufIndexCheck++;
// Log.d(LOG_TAG, " bufIndexCheck " + bufIndexCheck);
if (inputBufIndex >= 0) {
ByteBuffer dstBuf = codecInputBuffers[inputBufIndex];
int sampleSize =
extractor.readSampleData(dstBuf, 0 /* offset */);
//Log.d(LOG_TAG, "SampleLength = " + String.valueOf(sampleSize));
long presentationTimeUs = 0;
if (sampleSize < 0) {
Log.d(LOG_TAG, "saw input EOS.");
sawInputEOS = true;
sampleSize = 0;
} else {
presentationTimeUs = extractor.getSampleTime();
}
// can throw illegal state exception (???)
codec.queueInputBuffer(
inputBufIndex,
0 /* offset */,
sampleSize,
presentationTimeUs,
sawInputEOS ? MediaCodec.BUFFER_FLAG_END_OF_STREAM : 0);
if (!sawInputEOS) {
extractor.advance();
}
}
else
{
Log.e(LOG_TAG, "inputBufIndex " +inputBufIndex);
}
}
int res = codec.dequeueOutputBuffer(info, kTimeOutUs);
if (res >= 0) {
//Log.d(LOG_TAG, "got frame, size " + info.size + "/" + info.presentationTimeUs);
if (info.size > 0) {
noOutputCounter = 0;
}
int outputBufIndex = res;
ByteBuffer buf = codecOutputBuffers[outputBufIndex];
final byte[] chunk = new byte[info.size];
buf.get(chunk);
buf.clear();
audioTrack.write(chunk,0,chunk.length);
if(this.mState != State.Playing)
{
mDelegateHandler.onRadioPlayerPlaybackStarted(AudioTrackPlayer.this);
}
this.mState = State.Playing;
}
codec.releaseOutputBuffer(outputBufIndex, false /* render */);
if ((info.flags & MediaCodec.BUFFER_FLAG_END_OF_STREAM) != 0) {
Log.d(LOG_TAG, "saw output EOS.");
sawOutputEOS = true;
}
} else if (res == MediaCodec.INFO_OUTPUT_BUFFERS_CHANGED) {
codecOutputBuffers = codec.getOutputBuffers();
Log.d(LOG_TAG, "output buffers have changed.");
} else if (res == MediaCodec.INFO_OUTPUT_FORMAT_CHANGED) {
MediaFormat oformat = codec.getOutputFormat();
Log.d(LOG_TAG, "output format has changed to " + oformat);
} else {
Log.d(LOG_TAG, "dequeueOutputBuffer returned " + res);
}
}
Log.d(LOG_TAG, "stopping...");
relaxResources(true);
this.mState = State.Stopped;
doStop = true;
// attempt reconnect
if(sawOutputEOS)
{
try {
AudioTrackPlayer.this.play();
return;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(noOutputCounter >= noOutputCounterLimit)
{
mDelegateHandler.onRadioPlayerError(AudioTrackPlayer.this);
}
else
{
mDelegateHandler.onRadioPlayerStopped(AudioTrackPlayer.this);
}
}
Have you monitored the CPU frequency while your application is running? The CPU governor is probably scaling the CPU up on touch and scaling back down on a timer. Increasing the priority on your background thread to THREAD_PRIORITY_DEFAULT will probably fix the issue, the default priority for AsyncTask is quite low and not appropriate for Audio.
You could also increase the size of the AudioTrack's buffer to some multiple of the value returned by getMinBufferSize, that method only returns the minimum possible buffer for the Class to operate, it does not guarantee smooth playback.
This question already has an answer here:
StreamCorruptedException: invalid type code: AC
(1 answer)
Closed 5 years ago.
I am developing a multiplayer snake game. The game seems to be running fine except it often(not every time) randomly throws the java.io.StreamCorrupted Exception type code :AC
The full StackTrace of the same is given below.
java.io.StreamCorruptedException: invalid type code: AC
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readArray(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at mycode.ConnectionManager.otherRunMethod(ConnectionManager.java:231)
at mycode.ConnectionManager$1.run(ConnectionManager.java:289)
at java.lang.Thread.run(Unknown Source)
The Client side code where the error is generated is given below:
void otherRunMethod() {
try {
while (true) {
boolean gameup = false;
objin = new ObjectInputStream(socket.getInputStream());
Object insnake = objin.readObject();
if (((Snake) insnake).player.length() >= 9) {
if (((Snake) insnake).player.substring(0, 8).equals(
"Resigned")) {
String[] s = ((Snake) insnake).player.split(",");
map.remove(s[1]);
continue;
} else if (((Snake)insnake).player.substring(0, 10)
.equals("food_eaten")) {
String[] s = ((Snake) insnake).player.split(",");
Game.foodx = Integer.parseInt(s[1]);
Game.foody = Integer.parseInt(s[2]) + 35;
objin = new ObjectInputStream(socket.getInputStream());
insnake = objin.readObject();
if(((Snake)insnake).score>highestscore){
highestscore=((Snake)insnake).score;
if(highestscore>=100 && highestscore<200)
levelUp(2);
else if(highestscore>=200){
levelUp(4);
}
}
if (s.length == 4) {
System.out.println(s[3]);
if (s[3].equals("game_up")) {
gameup=true;
}
}
}
}
Snake temp = new Snake((Snake) insnake);
map.remove(temp.player);
map.put(temp.player, temp);
if(temp.gameover){
allPlayersEliminated();
}
findPos();
game_UpCheck(gameup);
Thread.sleep(10);
}
} catch (java.net.SocketException s) {
JOptionPane.showMessageDialog(null, "Server Closed", "ERROR",
JOptionPane.ERROR_MESSAGE);
System.exit(0);
} catch (Exception e) {
e.printStackTrace();
}
}
The corresponding server side code for the same is as follows:
void relay(Snake move) {
boolean foodeaten = false;
Snake snake = move;
try {
if (move != null && move.player.length() > 9) {
if (move.player.equals("food_eaten")) {
move.player = move.player + ","
+ (Snakeserver.randomGenerator.nextInt(100) * 6)
+ ","
+ (Snakeserver.randomGenerator.nextInt(100) * 6);
foodeaten = true;
snake = (Snake) objin.readObject();
int rows = Snakeserver.score.getModel().getRowCount();
int row = 1;
for (int i = 0; i < rows; i++) {
if (((Snake) snake).player
.equals((String) Snakeserver.score.getModel()
.getValueAt(i, 0))) {
row = i;
break;
}
}
if (snake.score >= 300)
move.player += "," + "game_up";
Snakeserver.score.getModel()
.setValueAt(snake.score, row, 1);
}
}
if (move.gameover) {
int rows = Snakeserver.score.getModel().getRowCount();
int row = 1;
for (int i = 0; i < rows; i++) {
if (snake.player.equals((String) Snakeserver.score
.getModel().getValueAt(i, 0))) {
row = i;
break;
}
}
Object temp = Snakeserver.score.getModel().getValueAt(row,
1);
temp += " GAME OVER";
Snakeserver.score.getModel().setValueAt(temp, row, 1);
}
for (Snake name : map.keySet()) {
if (name != null) {
if (name.player.equals(snake.player)) {
name.copyValues(snake);
}
objout = new ObjectOutputStream(map.get(name)
.getOutputStream());
objout.writeObject(move);
objout.flush();
if (foodeaten) {
objout = new ObjectOutputStream(map.get(name)
.getOutputStream());
objout.writeObject(snake);
objout.flush();
}
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Actually I don't know where the problem lies so I have perhaps dumped more code than necessary.
I finally found the solution to my problem after digging around for a few hours.
In the server side code see the following piece of code:
for (Snake name : map.keySet()) {
if (name != null) {
if (name.player.equals(snake.player)) {
name.copyValues(snake);
}
objout = new ObjectOutputStream(map.get(name)
.getOutputStream());
objout.writeObject(move);
objout.flush();
//rest of code goes here. Closing brackets as above.
If I write the line
objout = new ObjectOutputStream(map.get(name).getOutputStream());
before the compound statement
if (name.player.equals(snake.player)) {
name.copyValues(snake);
}
I seem to get rid of the StreamCorrupted Exception.
Any suggestions as to why this is happening would be most welcome.
I too faced same exception and issue as explained above, was,
while writing(sending) msg(object), I was creating new OutputObjectStream, as below
//client or server side
while(true)
{
ObjectOutputStream out = new ObjectOutputStream(s.getOutputStream());
out.writeObject(some_msg_object);
}
/* but while reading(receiving), I was not creating new inputObjectReader
ie */
//on other side
while(true)
Message msgReceived = (Message)inputObjectReader.readObject();
and this resulted above exact same education,
therefore, if sending msg, by creating new OutputStream, receive it by creating new InputStream viceversa, is sending using same already created OutputStream receive by already created InputStream.....
Using the Apache commons library, I am attempting to put a file or to list directory contents on the remote server that is connected using FTP over SSL.
public void outboundProcessFile(String inputFilePath, String outputFilePath) throws Exception {
File inFile = new java.io.File(inputFilePath);
if (args == null){
System.exit(-1) ;
}
String args[] = this.args;
boolean storeFile = false, binaryTransfer = false, error = false, listFiles = false, listNames = false, hidden = false;
boolean mlst = false, mlsd = false;
boolean lenient = true;
boolean feat = true;;
long keepAliveTimeout = 300000;
int controlKeepAliveReplyTimeout = 300000;
int minParams = 5;
String doCommand = "PROT P";//null
String server = null, password = null, username = null, remote = null,local = null;
int port = 990;//990
int base = 0;
for (base = 0; base < args.length; base++) {
if (args[base].equals("-s")) {
storeFile = true;
} else if (args[base].equals("-b")) {
binaryTransfer = true;
} else if (args[base].equals("-c")) {
doCommand = args[++base];
minParams = 3;
} else if (args[base].equals("-d")) {
mlsd = true;
minParams = 3;
} else if (args[base].equals("-h")) {
hidden = true;
} else if (args[base].equals("-k")) {
keepAliveTimeout = Long.parseLong(args[++base]);
} else if (args[base].equals("-l")) {
listFiles = true;
minParams = 3;
} else if (args[base].equals("-L")) {
lenient = true;
} else if (args[base].equals("-n")) {
listNames = true;
minParams = 3;
} else if (args[base].equals("-t")) {
mlst = true;
minParams = 3;
} else if (args[base].equals("-w")) {
controlKeepAliveReplyTimeout = Integer.parseInt(args[++base]);
} else if (args[base].equals("-sh")) {
server = args[++base];
String parts[] = server.split(":");
if (parts.length == 2){
server=parts[0];
port=Integer.parseInt(parts[1]);
}
} else if (args[base].equals("-u")) {
username = args[++base];
} else if (args[base].equals("-pw")) {
password = args[++base];
} else if (args[base].equals("-rf")) {
remote = null;
if (args.length - base > 0) {
remote = args[++base];
}
} else if (args[base].equals("-lf")) {
local = null;
if (args.length - base > 0) {
local = args[++base];
}
} else {
break;
}
}
FTPClient ftp;
FTPSClient ftps = new FTPSClient(true);
ftp = ftps;
ftps.setTrustManager(TrustManagerUtils.getAcceptAllTrustManager());
ftp.setCopyStreamListener(createListener());
if (keepAliveTimeout >= 0) {
ftp.setControlKeepAliveTimeout(keepAliveTimeout);
}
if (controlKeepAliveReplyTimeout >= 0) {
ftp.setControlKeepAliveReplyTimeout(controlKeepAliveReplyTimeout);
}
ftp.setListHiddenFiles(hidden);
// suppress login details
ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out), true));
try {
int reply;
if (port > 0) {
ftp.connect(server, port);
} else {
ftp.connect(server);
}
System.out.println("Connected to " + server + " on "+ftp.getRemotePort());
// After connection attempt, you should check the reply code to verify
// success.
reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
System.err.println("FTP server refused connection.");
System.exit(1);
}
}
catch (IOException e) {
if (ftp.isConnected()) {
try {
ftp.disconnect();
}
catch (IOException f)
{
// do nothing
}
}
System.err.println("Could not connect to server.");
e.printStackTrace();
System.exit(1);
}
__main:
try
{
String userid = null;//
if (!ftp.login(username, password)) {
ftp.logout();
error = true;
break __main;
}
System.out.println("Remote system is " + ftp.getSystemType());
if (feat) {
// boolean feature check
if (remote != null) { // See if the command is present
if (ftp.hasFeature(remote)) {
System.out.println("Has feature: "+remote);
} else {
if (FTPReply.isPositiveCompletion(ftp.getReplyCode())) {
// System.out.println("FEAT "+remote+" was not detected");
} else {
System.out.println("Command failed: "+ftp.getReplyString());
}
}
// Strings feature check
String []features = ftp.featureValues(remote);
if (features != null) {
for(String f : features) {
System.out.println("FEAT "+remote+"="+f+".");
}
} else {
if (FTPReply.isPositiveCompletion(ftp.getReplyCode())) {
// System.out.println("FEAT "+remote+" is not present");
} else {
System.out.println("Command failed: "+ftp.getReplyString());
}
}
} else {
if (ftp.features()) {
// Command listener has already printed the output
} else {
System.out.println("Failed: "+ftp.getReplyString());
}
}
}
ftp.doCommandAsStrings("PBSZ", "0");
ftp.doCommandAsStrings("PROT", "P");
if (binaryTransfer)
ftp.setFileType(FTP.ASCII_FILE_TYPE);//.BINARY_FILE_TYPE);
// Use passive mode as default because most of us are
// behind firewalls these days.
ftp.enterLocalPassiveMode();
ftp.doCommand("MLSD", "");
if (storeFile) {
InputStream input;
input = new FileInputStream(local);
ftp.changeWorkingDirectory(remote);
ftp.storeFile(local.substring(local.lastIndexOf("/")+1), input);
input.close();
} else if (listFiles) {
if (lenient) {
FTPClientConfig config = new FTPClientConfig();
config.setLenientFutureDates(true);
ftp.configure(config );
}
for (FTPFile f : ftp.listFiles(remote)) {
System.out.println(f.getRawListing());
System.out.println(f.toFormattedString());
}
} else if (mlsd) {
for (FTPFile f : ftp.mlistDir(remote)) {
System.out.println(f.getRawListing());
System.out.println(f.toFormattedString());
}
} else if (mlst) {
FTPFile f = ftp.mlistFile(remote);
if (f != null){
System.out.println(f.toFormattedString());
}
} else if (listNames) {
for (String s : ftp.listNames(remote)) {
System.out.println(s);
}
} else {
OutputStream output;
output = new FileOutputStream(local);
ftp.changeWorkingDirectory(remote);
ftp.retrieveFile(local.substring(local.lastIndexOf("/")), output);
output.close();
}
ftp.noop(); // check that control connection is working OK
ftp.logout();
} catch (FTPConnectionClosedException e) {
error = true;
System.err.println("Server closed connection.");
e.printStackTrace();
} catch (IOException e) {
error = true;
e.printStackTrace();
} finally {
if (ftp.isConnected()) {
try {
ftp.disconnect();
} catch (IOException f) {
// do nothing
}
}
}
System.exit(error? -1:0);
}
I run this and get console output for listing...
220 Serv-U FTP Server v6.4 for WinSock ready...
Connected to ftps.server.com on 990
USER *******
331 User name okay, need password.
PASS *******
230 User logged in, proceed.
SYST
215 UNIX Type: L8
Remote system is UNIX Type: L8
FEAT
211-Extension supported
AUTH TLS
SSCN
PBSZ
PROT
CCC
CLNT
MDTM
MDTM YYYYMMDDHHMMSS[+-TZ];filename
SIZE
SITE PSWD;EXEC;SET;INDEX;ZONE;CHMOD;MSG
REST STREAM
XCRC filename;start;end
MODE Z
MLST Type*;Size*;Create;Modify*;Win32.ea*;
211 End
PBSZ 0
200 PBSZ command OK. Protection buffer size set to 0.
PROT P
200 PROT command OK. Using private data connection.
TYPE A
200 Type set to A.
MLSD
150 Opening BINARY mode data connection for MLSD.
PASV
227 Entering Passive Mode (204,124,192,88,195,82)
LIST Directory/toIC/
425 Try later, data connection in use.
NOOP
150 Opening BINARY mode data connection for MLSD.
QUIT
200 Command okay.
If I do not MLSD and attempt to upload a file, I will see a 0 byte file with the file name placed on the server (via FileZilla) and I will get a 421 error. Ideas?
I had to remove the MLSD command. I can now list, retrieve and stor.