06-16-2009, 11:26 AM
Join Date: Jun 2009
Post Thanks: 0
Thanked 0 Times in 0 Posts
| | Blackberry FTP Program
Please Login to Remove!
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());
throw new Exception("Failure occured at the beginning of the download.");
FileOutputStream fileWriter = new FileOutputStream(File.FILESYSTEM_PATRIOT, destinationLocation);
int i = 0;
while ((i = dataDownload.read()) != -1)
//Close the streams
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 11:30 AM.