BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 10-25-2007, 01:25 AM   #1 (permalink)
Knows Where the Search Button Is
 
Join Date: Oct 2007
Model: 8700
PIN: N/A
Carrier: none
Posts: 23
Post Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation transfer files to an ftp site

Please Login to Remove!

can we write any j2me program that would transfer files from blackberry to an ftp location. if so can u help regarding this .


would really appreciate for a response
thanks in advance
Offline  
Old 10-25-2007, 04:36 AM   #2 (permalink)
CrackBerry Addict
 
Join Date: Jun 2005
Location: Manchester, UK
Model: BOLD
Carrier: t-mobile
Posts: 714
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

write a server-side script to take an uploaded file and use http post from the blackberry to send it.
__________________
new job doesn't allow a public profile - please do not contact this user with questions, you will not get a response. good luck!
Offline  
Old 10-25-2007, 10:21 AM   #3 (permalink)
Knows Where the Search Button Is
 
Join Date: Oct 2007
Model: 8700
PIN: N/A
Carrier: none
Posts: 23
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

server side script which would be easier jsp, php please advice
Offline  
Old 10-25-2007, 10:56 AM   #4 (permalink)
CrackBerry Addict
 
Join Date: Jun 2005
Location: Manchester, UK
Model: BOLD
Carrier: t-mobile
Posts: 714
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

just google for 'jsp file upload' or 'php file upload' - personally i find php about 100 times easier to work with than jsp...
__________________
new job doesn't allow a public profile - please do not contact this user with questions, you will not get a response. good luck!
Offline  
Old 10-26-2007, 12:56 AM   #5 (permalink)
Knows Where the Search Button Is
 
Join Date: Oct 2007
Model: 8700
PIN: N/A
Carrier: none
Posts: 23
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

i have one more doubt is there a different way to write an jsp or php program to run in blackberry.
Offline  
Old 10-26-2007, 03:59 AM   #6 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

php/jsp are server-side technologies, they don't "run" on blackberry. all you need is open an http-connection and put your file to a certain url, like http://yourserver.com/fileupload.jsp
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 10-27-2007, 12:47 AM   #7 (permalink)
Knows Where the Search Button Is
 
Join Date: Oct 2007
Model: 8700
PIN: N/A
Carrier: none
Posts: 23
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

i have written a j2me program that gets the file . now i have mentioned a url in which i have specified my jsp program which is placed in my web server (tomcat server). now how would the jsp program get the file . can u help me in regarding this . can i save the file as such in the filesystem of windows or should i put in one databse.

the file which iam is image file/txt file. iam using blackberry 4.2 jde . please guide me

Last edited by banu_berry : 10-27-2007 at 12:49 AM.
Offline  
Old 10-27-2007, 01:19 AM   #8 (permalink)
Knows Where the Search Button Is
 
Join Date: Oct 2007
Model: 8700
PIN: N/A
Carrier: none
Posts: 23
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default please help

this is the j2me program . i get this in my debug area as

the file got
url:http://myserver/post.jsp

-----------------------------4664151417711
Content-Disposition: form-data; name="uploadedfile"; filename=""
Content-Type: image/jpeg


open os
-----------------------------4664151417711
Content-Disposition: form-data; name="uploadedfile"; filename=""
Content-Type: image/jpeg


write:0
write:1024
write:2048
write:3072
write:4096
write:5120
write:6144
write:7168
write:8192
write:9216
write:10240
write:11264
write:12288
write:13312
write:14336
write:15360
write:16384
write:17408
write:18432
write:19456
write:20480
write:21504
write:22528
write:23552
write:24576
write:25600
write:26624
write:27648
write:28672
write:29696
write:30720
write:31744
write:32768
write:33792
write:34816
write:35840
write:36864
write:37888
write:38912
written:39259

-----------------------------4664151417711--






/*
* PostFile.java
*
* <your company here>, 2003-2005
* Confidential and proprietary.
*/

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import javax.microedition.io.file.*;
//import net.rim.device.api.system.*;
import java.io.*;

public class PostFile extends MIDlet implements Runnable, CommandListener{


private final String URL = "http://myserver/post.jsp";

private final String CrLf = "\r\n";

private Form form = null;
private Gauge gauge = null;
private Command exitCommand;
private Command uploadCommand;

public PostFile(){
form = new Form("Upload File");
gauge = new Gauge("Progress:", true, 100, 0);
form.append(gauge);

exitCommand = new Command("Exit", Command.EXIT, 0);
uploadCommand = new Command("Upload", Command.SCREEN, 0);
form.addCommand(exitCommand);
form.addCommand(uploadCommand);

form.setCommandListener(this);
}

public void startApp() {
Display.getDisplay(this).setCurrent(form);
}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
}

private void progress(int total, int current){
int percent = (int) (100 * ((float)current/(float)total));
gauge.setValue(percent);
}

public void run() {
httpConn();
}

private void httpConn(){
HttpConnection conn = null;
OutputStream os = null;
InputStream is = null;

try{

String str="";


FileConnection fcon = (FileConnection)Connector.open("file:///store/samples/pictures/Waterfall.jpg");
InputStream imgIs = fcon.openInputStream();
byte []imgData = new byte[imgIs.available()];
imgIs.read(imgData);
System.out.println("the file got");

System.out.println("url:" + URL);
conn = (HttpConnection)Connector.open(URL);
conn.setRequestMethod(HttpConnection.POST);

String postData = "";


String message1 = "";
message1 += "-----------------------------4664151417711" + CrLf;
message1 += "Content-Disposition: form-data; name=\"uploadedfile\"; filename=\"" + str + "\"" + CrLf;
message1 += "Content-Type: image/jpeg" + CrLf;
message1 += CrLf;
System.out.println(str);
System.out.println(message1);

// the image is sent between the messages in the multipart message.

String message2 = "";
message2 += CrLf + "-----------------------------4664151417711--" + CrLf;

conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=---------------------------4664151417711");
// might not need to specify the content-length when sending chunked data.
// conn.setRequestProperty("Content-Length", String.valueOf((message1.length() + message2.length() + imgData.length)));

System.out.println("open os");
os = conn.openOutputStream();

System.out.println(message1);
os.write(message1.getBytes());

// SEND THE IMAGE
int index = 0;
int size = 1024;
do{
System.out.println("write:" + index);
if((index+size)>imgData.length){
size = imgData.length - index;
}
os.write(imgData, index, size);
index+=size;
progress(imgData.length, index); // update the progress bar.

}while(index<imgData.length);
System.out.println("written:" + index);

System.out.println(message2);
os.write(message2.getBytes());
os.flush();

System.out.println("open is");
is = conn.openInputStream();

char buff = 512;
int len;
byte []data = new byte[buff];
do{
System.out.println("READ");
len = is.read(data);

if(len > 0){
System.out.println(new String(data, 0, len));
}
}while(len>0);

System.out.println("DONE");

}catch(Exception e){
e.printStackTrace();
}finally{
System.out.println("Close connection");
try{
os.close();
}catch(Exception e){}
try{
is.close();
}catch(Exception e){}
try{
conn.close();
}catch(Exception e){}
}
}

public void commandAction(javax.microedition.lcdui.Command command, javax.microedition.lcdui.Displayable displayable) {
if(command == exitCommand){
this.notifyDestroyed();
}else if(command == uploadCommand){
new Thread(this).start();
}
}
}
can u please help me.if i need to do any corrections.and let me know whether my program is correct

Last edited by banu_berry : 10-27-2007 at 02:18 AM.
Offline  
Old 10-27-2007, 02:32 AM   #9 (permalink)
Knows Where the Search Button Is
 
Join Date: Oct 2007
Model: 8700
PIN: N/A
Carrier: none
Posts: 23
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

System.out.println("open is");
is = conn.openInputStream();

char buff = 512;
int len;
byte []data = new byte[buff];
do{
System.out.println("READ");
len = is.read(data);

if(len > 0){
System.out.println(new String(data, 0, len));
}
}while(len>0);

System.out.println("DONE");


this part of the code is not executing please let me know if i have to make any changes


thanks in advance
Offline  
Old 10-29-2007, 04:15 AM   #10 (permalink)
Talking BlackBerry Encyclopedia
 
Skipper_Joe's Avatar
 
Join Date: Jan 2007
Location: Kharkov, Ukraine
Model: 8300
Carrier: N/A
Posts: 237
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

google for "jsp how to upload file to server"
Offline  
Old 10-29-2007, 06:28 AM   #11 (permalink)
Knows Where the Search Button Is
 
Join Date: Oct 2007
Model: 8700
PIN: N/A
Carrier: none
Posts: 23
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks for ur help.and reference i would surely refer it. actually its easier to transfer a text file but how to transfer an image file. do we have to encode it and send . if so can u tell me the method in blackberry jde and midlet
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.