How can i upload file from sdcard to SFTP server in Android?

Go To


I am using JSch library to upload file from sdcard to SFTP server but it's generate such error

04-04 14:29:02.609: W/System.err(10706): 3: Permission denied
04-04 14:29:02.609: W/System.err(10706):    at com.jcraft.jsch.ChannelSftp.throwStatusError(
04-04 14:29:02.609: W/System.err(10706):    at com.jcraft.jsch.ChannelSftp._put(
04-04 14:29:02.609: W/System.err(10706):    at com.jcraft.jsch.ChannelSftp.put(

My code is

public class FileUploadActivity extends Activity {
/** Called when the activity is first created. */
Channel channel = null;
ChannelSftp c = null;
public void onCreate(Bundle savedInstanceState) {

    final String host="192.***.*.**";
    final String username="*****123";
    final String password="****123";
    try {
        Session session=connectSFTP(host, username, password);
        channel = session.openChannel("sftp");
        c = (ChannelSftp) channel;"/home/*****11/doc");
        String inputFileName =Environment.getExternalStorageDirectory().getAbsolutePath()+"/demo/enck.pdf";
        File f = new File(inputFileName);  
        c.put(inputFileName, "/home/*****11/doc/enck.pdf");
    } catch (Exception e) {
        // TODO: handle exception
        System.err.println("Unable to connect to FTP server."
                + e.toString());
public Session connectSFTP(String host,String username,String password){
    Session session= null;
        JSch js = new JSch();
        session = js.getSession(username, host, 22);
        java.util.Properties config = new java.util.Properties();
        config.put("StrictHostKeyChecking", "no");
    }catch (Exception e) {
        // TODO: handle exception
        Toast.makeText(getBaseContext(), "Unable to connect Your SFTP Serve"+e, Toast.LENGTH_SHORT);
    return session;
2012-04-04 06:32
by Bhargav Panchal


Obvious things to check:

  • Does your application have permission to read from the SD card?
  • Does the user you're logging in with have permission to write to that destination?

From the location of the exception, I deduce that you do have permission to access the internet, but that's also worth double-checking.

2012-04-04 10:53
by Andrew Aylett