Android commons net ftp FTPClient send small file issue - android

I have an issue with Apache commons-net-ftp library. What I do is send a small size MP3 files. The sizes are between 1 and 10 kb. All stages of algorithm pass well but there are NO files on FTP.
This is overview of the algorithm:
ftpClient.connect(InetAddress.getByName(mServerName));
ftpClient.login(mLogin, mPassword);
ftpClient.changeWorkingDirectory(mWorkingDir);
if (ftpClient.getReplyString().contains("250")) {
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
BufferedInputStream buffIn = new BufferedInputStream(new FileInputStream(fullPathToLocalFile));
ftpClient.enterLocalPassiveMode();
ProgressInputStream progressInput = new ProgressInputStream(buffIn, callBack);
boolean result = ftpClient.storeFile(serverFileName, progressInput);
buffIn.close();
ftpClient.logout();
ftpClient.disconnect();
}
And this is out put:
FTP Uploader
- server: ftp.***.**.**
- login: freer_********
- password: ********
FTP Uploader upload file 1367302998934.mp3 full path /mnt/sdcard/Android/data/*********.*****.********/files/mp3/1367302998934.mp3
FTP replay: 250 OK. Current directory is /htdocs/mp3
ProgressInputStream update 1024
ProgressInputStream update 2048
ProgressInputStream update 3072
ProgressInputStream update 4070
ProgressInputStream update 4070
FTP result: true
As You see, all outputs are point to normal behavior but the is NO file on FTP server.
Does anyone has experience with same problem ?

Sorry guys for the post, the answer was very clear ...
The host provider I used has a service to monitor "mp3" content. It not allow to use mp3 files to store on the host.
P.S. I wish to close this post but I don't know how.

Related

Converting Image To PCL And Printing Via Bluetooth

Problem:
Using an Android device, without internet / network connection, I have to print images to a bluetooth enabled printer.
Be aware that this is the business case — I cannot use Google Cloud Print, nor can I use PrinterShare or anything else like that. The data generated by the app is medical in nature and must be kept confidential and within the app.
What I’ve accomplished:
Generating PCL data (text only, no images) to send to a bluetooth connection that the printer can process and output.
What I’ve tried:
Generating PCL data (image) using the Android ImageMagick port (found here: https://github.com/paulasiimwe/Android-ImageMagick) and sending the generated PCL data to the bluetooth connection.
Result:
Gibberish, but gibberish that appears to be the right dimensions of the image I am trying to print.
==============
My hypothesis is that there’s something slightly off in my implementation of the conversion, but I’m not sure what it is.
Sample Code:
NOTE: this is proof of concept work and captures an image from the Assets dir, makes it available, and then converts it.
// Attempt to get image file from Assets folder
AssetManager assetManager = context.getAssets();
InputStream istr = assetManager.open("test.jpg");
Bitmap bitmap = BitmapFactory.decodeStream(istr);
// Access External Storage Directory and save file
String root = Environment.getExternalStorageDirectory().toString();
File tempDirectory = new File(root + "/temp");
tempDirectory.mkdirs();
String fileName = "test.jpg";
File file = new File (tempDirectory, fileName);
try {
FileOutputStream out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
out.flush();
out.close();
} catch (Exception exception) {
// Exception found
}
// Capture file of recently saved image, convert to PCL
try{
ImageInfo originalInfo = new ImageInfo(Environment.getExternalStorageDirectory().getAbsolutePath() + "/temp/test.jpg");
MagickImage mImage = new MagickImage(originalInfo);
String newInfoPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/temp/test.pcl";
mImage.setFileName(newInfoPath);
mImage.setImageFormat("pcl");
ImageInfo newInfo = new ImageInfo(newInfoPath);
mImage.writeImage(newInfo);
} catch (MagickException exception) {
// Exception found
}
I then retrieve the PCL file and send it to the bluetooth connection (using another method that works using standard PCL files), but as mentioned the output is gibberish.
I feel like I’m missing something simple, but I’m just not seeing it.
Also, I am seeing the following in LogCat that may / may not be related, but I haven't been able to find any information about resolving this nor can I determine if it's anything more than a warning.
V/Magick: ThrowException
V/Magick: severity: 395
V/Magick: reason: UnableToOpenConfigureFile `policy.xml' # warning/configure.c/GetConfigureOptions/589
V/Magick: Attempting to read from file /storage/emulated/0/temp/test.jpg
V/Magick: ThrowException
V/Magick: severity: 395
V/Magick: reason: UnableToOpenConfigureFile `magic.xml' # warning/configure.c/GetConfigureOptions/589
V/Magick: OpenPixelCache()
V/Magick: - cache_info->columns: 144
V/Magick: - cache_info->rows: 144
V/Magick: - cache_info->offset: 0
V/Magick: - cache_info->length: 165888
V/Magick: - length: 207360
V/Magick: - create memory pixel cache
V/Magick: ReadImage completed
Does anyone have any experience with this or can anyone point me in the right direction?

Use IPP(Internet Printing Protocol) or LPR(Line printer Remote) to print file in android

My requirement is to print a file from an android device without using any cloud based service.
I have been able to achieve it using "Raw" print protocol i.e by simply sending the file to printer's IP address at Port 9100. Here is the code snippet for that:
client = new Socket(ip,port); //Port is 9100
byte[] mybytearray = new byte[(int) file.length()]; //create a byte array to file
fileInputStream = new FileInputStream(file);
bufferedInputStream = new BufferedInputStream(fileInputStream);
bufferedInputStream.read(mybytearray, 0, mybytearray.length); //read the file
outputStream = client.getOutputStream();
outputStream.write(mybytearray, 0, mybytearray.length); //write file to the output stream byte by byte
outputStream.flush();
bufferedInputStream.close();
outputStream.close();
The problem with "Raw" printing protocol is that there is no way to get the status back from the printer.
So, I recently read about IPP and LDR using which we can get the status back from printer.
I have tried to find a way to implement them using android but had no success. I have already went through this answer but had no success in finding my solution.
It will be really helpful if someone can guide me on how to implement IPP or LDR in android.
Thanks in advance!
General usage of IPP:
Once a print job has been submitted the printer returns a job-id
Use the Get-Job-Attributes-Operation in order to get the current job-state
Wait until the attribute job-state equals to 9 (means 'completed')
There are other final job-states you should check for: aborted or canceled
For prototyping you could use the ipptool (native for desktop usage):
# ipptool -t -d job=482 ipp://192.168.2.113/ipp job.ipp
{
OPERATION Get-Job-Attributes
GROUP operation-attributes-tag
ATTR charset attributes-charset utf-8
ATTR language attributes-natural-language en
ATTR uri printer-uri $uri
ATTR integer job-id $job
}
Update 5/2020
I have published a kotlin implementation of the ipp protocol.
https://github.com/gmuth/ipp-client-kotlin
Once submitted you can wait for the print job to terminate: job.waitForTermination()

Uploading Downloading of large size file to Google Drive giving error

I am Creating a small Apps from that user can upload his MS office file to his registered mail ID G_Drive account from android device.
and export that file into PDF Format.
for that i taken help form below link :
https://developers.google.com/drive/v2/reference/files/insert#examples
https://developers.google.com/drive/manage-downloads#downloading_google_documents
i created application, and its working fine for small size(< 1MB) file, but when i am sending large size to the g_Drive than i am getting below errors:
java.io.exception Unexpected End of Stream
java.net.SocketTimeoutException: Read timed out
i tried for Resumable upload, but the insert method doesn't have parameter to set this.
if am setting the upload type to resumable with
service.files().insert(body, mediaContent).set("upload type", "resumable");
or
Insert insertService = service.files().insert(body, mediaContent).setConvert(true);
insertService.getMediaHttpUploader().setDirectUploadEnabled(false); insertService.getMediaHttpUploader().setChunkSize(MediaHttpUploader.DEFAULT_CHUNK_SIZE);
file = insertService.execute();
than also its generating same errors.
same case with downloading also.....
please send me some solutions...for this...
Don't use basic upload for files larger than 5MB.
You need to set the content length of the media content before starting to upload. Otherwise, it's likely that Google endpoint can't recognize the upload's being finished and it waits until the socket is being timed out.
InputStreamContent mediaContent = new InputStreamContent("image/jpeg", new BufferedInputStream(
new FileInputStream(UPLOAD_FILE)));
mediaContent.setLength(UPLOAD_FILE.length());
Insert insert = drive.files().insert(fileMetadata, mediaContent);
MediaHttpUploader uploader = insert.getMediaHttpUploader();
uploader.setDirectUploadEnabled(false);
uploader.setProgressListener(new FileUploadProgressListener());
insert.execute();
There is actually a complete Android based resumable upload sample on [1].

UTF-8 with apache commons-net

I have problem with Unicode, when I save file in arabic name on sdcard, all things will be good, but when file uploaded to ftp server by commons-net, I will get file name as pic
any solution please?
This is a part of code which related with FTPClient:
FTPClient ftpClient = new FTPClient();
try {
FTPClientConfig conf = new FTPClientConfig(FTPClientConfig.SYST_NT);
conf.setServerLanguageCode("ar");
ftpClient.configure(conf);
ftpClient.setControlEncoding("UTF-8");
ftpClient.setAutodetectUTF8(true);
ftpClient.connect(server, port);
ftpClient.login(user, pass);
ftpClient.enterLocalPassiveMode();
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
Using filenames in non-latin letters will cause a lot of problems. Many programs will not load or display such files. I would question myself, if there is really a need in this naming of files.

Upload file to FTP

I'm trying to upload a file to an FTP using apache commons ftp.
I am using a code that I have seen on several websites, including stackoverflow
Android FTP Library
The problem is that in the line:
Buffin = new BufferedInputStream (new FileInputStream (file));
I can not put any paths in "file", eclipse does not validate any values ​​or path-
What would have to indicate in "new FileInputStream"?
I do not know I'm doing wrong.
Thank you very much and best regards
You need a File object to pass it to the FileInputStream.
Buffin = new BufferedInputStream(new FileInputStream(new File("/path/to/file"));
And you can't Upload file to FTP because FTP is not a place, it is a protocol.
Create a File object with the path and pass it in.
You can do this:
Buffin = new BufferedInputStream (new FileInputStream (<path to your file>));
Details here:
FileInputStream

Categories

Resources