Monday, 17 August 2015

java - How do you upload a file to an FTP server?

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystemOptions;
import org.apache.commons.vfs2.Selectors;
import org.apache.commons.vfs2.impl.StandardFileSystemManager;
import org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder;

public void onUpload()
String hostName = "xxxxxxx";
String username = "xxxxxxx";
String password = "xxxxxxx";
String ftpfolder = "outbound";

String fileName ="YourLocalFileName";
String remoteFilePath = "/" + ftpfolder + "/" + fileName;
String localFilePath = "YourLocalFilePath";
File file = new File(localFilePath);
if (!file.exists())
throw new RuntimeException("Error. Local file not found");

StandardFileSystemManager manager = new StandardFileSystemManager();
try {

// Create local file object
FileObject localFile = manager.resolveFile(file.getAbsolutePath());

// Create SFTP options
FileSystemOptions opts = new FileSystemOptions();

// SSH Key checking
opts, "no");
// Root directory set to user home

// Timeout is count by Milliseconds
SftpFileSystemConfigBuilder.getInstance().setTimeout(opts, 10000);

// Create remote file object
FileObject remoteFile = manager.resolveFile(
createConnectionString(hostName, username, password,
remoteFilePath), opts);

// Copy local file to sftp server
remoteFile.copyFrom(localFile, Selectors.SELECT_SELF);
} catch (Exception e) {
//Catch and Show the exception
} finally {

public static String createConnectionString(String hostName,
String username, String password, String remoteFilePath) {
return "sftp://" + username + ":" + password + "@" + hostName + "/"
+ remoteFilePath;

Maven artifacts for Apache VFS is a Virtual File System library.



  1. Your blog is very informative, thanks for sharing it.  E-Health Care Lists is one of the global suppliers of healthcare mailing list & email list. Marketing to the healthcare industry, reaching the doctors and other healthcare decision makers is often an impossible task. Healthcare Mailing List


    1. genuine antivirus for 1 year , windows 7 pro sp1 keys and download , microsoft office 2007 professional key for sale , windows vista anytime upgrade free keygen , windows 7 kei , outlook 2010 product code , buy server 2013 r2 keys , oem key windows 7 , lRU7sh

      windows 7 ult key sale online

      buy office pro plus 2016 keys

      cheap windows 10 pro keys for sale

      windows server 2016 standard key sale and download

      buy windows 7 ult keys online

  2. This coding is really worked and so nice thanks admin for sharing this information.

    Render Cleaning Company
    K Rend Services

  3. Wow! I’m from Malaysia, an English teacher gonna be. Now, I know that my goal readers are my students in the past. custom essay writing service I’d like to mark like this too attractive event and real hard work to make an enormous article. Thank you for the suggestions, I really enjoyed reading this. It is so much inspiring.

  4. High technology WebRTC allowing high quality communications online between doctors and patients. healthcare mobile apps

  5. Nowadays some healthcare providers have begun to rely heavily on technology. healthcare mobile apps allows patients email and video chat with physicians and schedule appointments. They are not only convenient for patients but also for physicians.

  6. At Savvycom – A software development company, we have been offering strategic IT solutions to our clients since 2009, specifically, Savvycom’s domain technology is in healthcare mobile apps that build adherence and engagement. Our healthcare mobile app developers with their seasoned experience and passion for IT offer development services that are always in alignment with the clients’ vision as well as bring the greatest experience to both physicians and patients.

  7. With mobile devices becoming more widely used, mobility has been increasingly adopted in the healthcare industry to improve, design and transform healthcare. From making connecting physicians and patients easier through technology to affording busy nurses precious extra time, mobile apps have brought benefits to stakeholders. Hospitals and patients alike gain benefits from the power of text, voice, and real time critical data access that healthcare mobile app developers provide through modern mobility. Mobility is expected to address issues healthcare facing today such profitability pressures or patient satisfaction.

  8. Microsoft office has a different version, and the entire version has the different setup file. Some of the version is Office 2013, Office 2016 and Office 365 etc. Go to and redeem your key. Office Com Setup is one of the most popular productivity programs around. If you have your product key handy, you don't even need a disc to start installing Office just visit office setup help. Norton is one of the most reliable antivirus providers in the market to download visit . There are multiple manufacturers making printers for home and office use with varied range as printer series per the need and affordability of different customers. Printer Tech Support. It has become one of the most useful computer hardware devices that allow people to convert computer generated typescript into a physical printed document.

  9. contact for seo, smo, internet marketing and consulting....seo Company in noida sector 10

  10. Amazing article. You are article is fabulous and informative. Thank you for sharing such article with us.

  11. Microsoft office has a different version, and the entire version has the different setup file set up . Some of the version is Office 2013, Office 2016 and Office 365 etc. Go to . Norton is one of the most reliable antivirus providers in the market. Norton is delivering top rated protection from mobile devices and computers. Norton has 3 antivirus packages norton com setup McAfee have the complete set of features which can protect your digital online and offline life of the computing devices, and it not only help you to protect it install mcafee.If your PC is having a slow performance and you are facing problems due to this, then we can provide a solution to that. avira tech support . Our Avira Customer Support is open to those who have issues relating to downloading, updating or upgrading Avira Antivirus software avira antivirus phone number .We can also assist you to confirm your product if you are not sure about its validity. avira refund .

  12. Thank you for sharing, we specialize in providing you health care equipment, you can find out information here

    Lều xông hơi loại nào tốt

    Lều xông hơi gia đình

    Bán lều xông hơi

    Xông hơi hồng ngoại