Following is the code that's suppose to create a text document and upload it to my FTP server. For some reason it doesn't seem to work. I used to the libraries provided at
http://lavalatwork.blogspot.tw/2010/09/using-apache-commons-ftp-library-in.html
for communicating with the FTP server.
try
{
final String testString = new String("Hello");
FileOutputStream fOut = openFileOutput("samplefile.txt",
MODE_WORLD_READABLE);
OutputStreamWriter osw = new OutputStreamWriter(fOut);
osw.write(testString);
osw.flush();
osw.close();
}
catch(IOException ex)
{
}
FTPClient mFTP = new FTPClient();
try {
// Connect to FTP Server
mFTP.connect("192.168.10.101");
//mFTP.login("user", "password");
mFTP.setFileType(FTP.BINARY_FILE_TYPE);
mFTP.enterLocalPassiveMode();
// Prepare file to be uploaded to FTP Server
File file = new File(getFileStreamPath("samplefile.txt")+ "");
FileInputStream ifile = new FileInputStream(file);
// Upload file to FTP Server
mFTP.storeFile("filetotranfer",ifile);
mFTP.disconnect();
} catch (SocketException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Any help would be appreciated.
You can use Simple Java FTP Client and add it as external jar for your project, you can also refer to this link
You can also use the Apache commons-net-ftp library, for more details you can focus on this link.
See this...... This will help you rectify the probs in your code.
I have used the apache's commons library to upload and download an Audio file to and from the Server... see this...
Uploading:
Downloading:
Here is the code block :
Please get complete working project for uploading files to FTP server from below drive.
File uploading to FTP is used PORT 21, required parameter to upload file on FTP..
host name username password
https://drive.google.com/file/d/0B80LBJs3JkaDYUNfZ3pDSkVJUDA/edit