BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 06-16-2009, 10:26 AM   #1 (permalink)
New Member
 
Join Date: Jun 2009
Model: 8300
PIN: N/A
Carrier: Verizon
Posts: 1
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Blackberry FTP Program

Please Login to Remove!

Hello,

I have been able to successfully implement a connect() method by doing the following:

connection = (SocketConnection)Connector.open("socket://" + host+ ":" + port + ";deviceside=true");
download = new InputStreamReader(connection.openInputStream());
upload = new OutputStreamWriter(connection.openOutputStream());

I am able to connect and send commands to the FTP server to create folders, rename files, change the directory, etc. They have been fully tested and I am sure they work.

The challenge now is to be able to create an additional socket to port 20 for data transfer. This is where I am running into issues. I feel that my logic is sound, but I am new to the Blackberry API. This is my download method so far:

public void download(String requestedFile, String destinationLocation) throws Exception
{
String response = sendFTPCommand("RETR " + requestedFile);

SocketConnection dataConnection = (SocketConnection)Connector.open("socket://" + host + ":20;deviceside=true");
InputStreamReader dataDownload = new InputStreamReader(dataConnection.openDataInputStre am());

if(!response.startsWith("150 "))
throw new Exception("Failure occured at the beginning of the download.");

try
{
FileOutputStream fileWriter = new FileOutputStream(File.FILESYSTEM_PATRIOT, destinationLocation);

int i = 0;
while ((i = dataDownload.read()) != -1)
{
fileWriter.write(i);
}

//Close the streams
dataDownload.close();
fileWriter.close();
}
catch(Exception e)
{
System.err.println(requestedFile + " cannot be found.");
}
}
When I run the program, I get the following error:
java.io.IOException: Peer refused the connection

I have experimented with a lot of different ideas, but none of them worked. Any help would be appreciated.

Last edited by russkie : 06-16-2009 at 10:30 AM.
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

MEMORY MODULE/ASSEMBLY INFINEON HYS72V64200GR-8A-A 72V64200GR8 HYS72V64200GR8AA
$62.08
MEMORY MODULE/ASSEMBLY INFINEON HYS72V64200GR-8A-A 72V64200GR8 HYS72V64200GR8AA picture20-PCS MEMORY IC ST93CS46-B1 SGS-THOM 93CS46B1 ST93CS46B1
$40.98
20-PCS MEMORY IC ST93CS46-B1 SGS-THOM 93CS46B1 ST93CS46B1 picture10-PCS MEMORY IC KM6164002AJ-20 SAMSUNG 6164002AJ20 KM6164002AJ20
$76.42
10-PCS MEMORY IC KM6164002AJ-20 SAMSUNG 6164002AJ20 KM6164002AJ20 picture10-PCS MEMORY IC KM736V787T-9 SAMSUNG 736V787T9 KM736V787T9
$61.52
10-PCS MEMORY IC KM736V787T-9 SAMSUNG 736V787T9 KM736V787T9 picture2-PCS MEMORY IC KM718V887T-9 SAMSUNG 718V887T9 KM718V887T9
$67.75
2-PCS MEMORY IC KM718V887T-9 SAMSUNG 718V887T9 KM718V887T9 picture






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