I am uploading a file from my local computer to remote server in a simple java application using Jsch, and Sftp protocol. 

My code is getting no error or no exception and it runs successfully, but when I look at the remote location, the file is uploaded as 0kb with no extension and named as 'D'. 

I have tried many ways but I am not able to figure out the mistake. 

Here is my code..

```
        String remoteDirectory = "D:\\Datastores\\RootStore\\Test\\";
        String localDirectory = "C:\\pdffiles\\";

        String fileToFTP = "demo.pdf";
        String SFTPHOST = "hostIPaddress";
        int SFTPPORT = 22;
        String SFTPUSER = "username";
        String SFTPPASS = "password";

        String local_filename = fileToFTP;
        String local_pathname = localDirectory;
        String remote_filename = fileToFTP;

        JSch jsch = null;
        Session session = null;
        ChannelSftp sftpChannel = null;

        try
        {
          jsch = new JSch();
          session = jsch.getSession(SFTPUSER, SFTPHOST);
          session.setPassword(SFTPPASS);
          session.setPort(SFTPPORT);
          session.setConfig("StrictHostKeyChecking", "no");
          session.setConfig("cipher.s2c", "aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc,aes192-cbc,aes256-cbc,aes256-ctr");
          session.setConfig("cipher.c2s", "aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc,aes192-cbc,aes256-cbc,aes256-ctr");
          session.connect();

          sftpChannel = (ChannelSftp)session.openChannel("sftp");
          sftpChannel.connect();

          System.out.println(sftpChannel);
          System.out.println(sftpChannel.getSession().isConnected());

          FileInputStream fileBodyIns = new FileInputStream(local_pathname + local_filename);

          System.out.println(local_pathname + local_filename);
          System.out.println(remoteDirectory + remote_filename);

          sftpChannel.put(fileBodyIns, remoteDirectory + remote_filename);
          fileBodyIns.close();

          sftpChannel.exit();
          session.disconnect();

          System.out.println("File uploaded successfully");
          return "File uploaded successfully";
        }
        catch (Exception e)
        {
            e.printStackTrace();
            return e.getMessage();
        }

```

My connection makes successfully, the line

```
System.out.println(sftpChannel.getSession().isConnected());

```

gives **true**

and the following line prints successfully

```
System.out.println("File uploaded successfully");

```