Академический Документы
Профессиональный Документы
Культура Документы
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
catch(IOException ex)
{
Checking the output of logcat is often very helpful when using Apache Commons FTP client. Dheeraj V.S. Jul 22 '12 at
14:53
1 Please be explicit about what exactly does not work. And post your logcat. Dheeraj V.S. Jul 22 '12 at 14:56
add a comment
2 Answers order by votes
See this...... This will help you rectify the probs in your code.
12
I have used the apache's commons library to upload and download an Audio file to and from the
Server... see this...
Uploading:
try
{
con = new FTPClient();
con.connect("192.168.2.57");
if (con.login("Administrator", "KUjWbk"))
{
con.enterLocalPassiveMode(); // important!
con.setFileType(FTP.BINARY_FILE_TYPE);
String data = "/sdcard/vivekm4a.m4a";
try
{
con = new FTPClient();
con.connect("192.168.2.57");
if (con.login("Administrator", "KUjWbk"))
{
con.enterLocalPassiveMode(); // important!
con.setFileType(FTP.BINARY_FILE_TYPE);
String data = "/sdcard/vivekm4a.m4a";
You can use Simple Java FTP Client and add it as externel jar for your projec, you can also refer to
1 this link
public class FileUpload
{
/**
* Upload a file to a FTP server. A FTP URL is generated with the
* following syntax:
* ftp://user:password@host:port/filePath;type=i.
*
* @param ftpServer , FTP server address (optional port ':portNumber').
* @param user , Optional user name to login.
* @param password , Optional password for user.
* @param fileName , Destination file name on FTP server (with optional
* preceding relative path, e.g. "myDir/myFile.txt").
* @param source , Source file to upload.
* @throws MalformedURLException, IOException on error.
*/
public void upload( String ftpServer, String user, String password,
String fileName, File source ) throws MalformedURLException,
IOException
{
You can also use the Apache commons-net-ftp library, for more details you can focus on this link.
import org.apache.commons.net.ftp.FTPClient;
try {
ftpClient.connect(InetAddress.getByName(SERVER));
ftpClient.login(USERNAME, PASSWORD);
ftpClient.changeWorkingDirectory(PATH);
if (ftpClient.getReplyString().contains("250")) {
ftpClient.setFileType(org.apache.commons.net.ftp.FTP.BINARY_FILE_TYPE);
BufferedInputStream buffIn = null;
buffIn = new BufferedInputStream(new FileInputStream(FULL_PATH_TO_LOCAL_FILE
ftpClient.enterLocalPassiveMode();
ProgressInputStream progressInput = new ProgressInputStream(buffIn, progressHandle
K_Anas answered
22k 5 43 71 Jul 22 '12 at 14:52
Your Answer
Body
Add picture
Log in
OR
Name
By posting your answer, you agree to the privacy policy and terms of service.
meta chat tour help blog privacy policy legal contact us full site