hello all i am developing an android app that has an functionality of uploading files to ftp server i want my app to upload an Html file to ftp server i am using this code--- please answere. Thanx in advance... here goes the code.. only the main code..
new Thread(new Runnable() {
@Override
public void run() {
String host = "www.ethicstrain.tk";
String user = "user";
String pass = "pass";
String filePath = Environment.getExternalStorageDirectory()+"index.htm";
String uploadPath = "public_html/"+str+"/index.htm"; // str is input from editText.
String filename = "index.html";
StringBuffer sb = new StringBuffer( "ftp://" );
sb.append( user );
sb.append( ':' );
sb.append( pass);
sb.append( '@' );
sb.append( server );
sb.append( '/' );
sb.append( str );
sb.append( '/');
sb.append(filename);
sb.append( ";type=i" );
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try
{
URL url = new URL( sb.toString() );
URLConnection urlc = url.openConnection();
bos = new BufferedOutputStream( urlc.getOutputStream() );
bis = new BufferedInputStream( new FileInputStream(filePath ) );
int i;
// read byte by byte until end of stream
while ((i = bis.read()) != -1)
{
bos.write( i );
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
if (bis != null)
try
{
bis.close();
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
if (bos != null)
try
{
bos.close();
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
}
}).start();
and the Logcat:
07-05 09:46:28.055: W/System.err(1123): java.io.IOException: Unable to connect to server: null
07-05 09:46:28.055: W/System.err(1123): at libcore.net.url.FtpURLConnection.connect(FtpURLConnection.java:203)
07-05 09:46:28.055: W/System.err(1123): at libcore.net.url.FtpURLConnection.getOutputStream(FtpURLConnection.java:339)
07-05 09:46:28.065: W/System.err(1123): at dolphin.developers.com.facebook1$DownloadFileFromURL$3.run(facebook1.java:382)
07-05 09:46:28.065: W/System.err(1123): at java.lang.Thread.run(Thread.java:856)
No comments:
Post a Comment