Reputation: 11
f.connect("ftp.drivehq.com",21);
if(f.login("XXXX", "XXX"))
{
f.enterLocalPassiveMode();
f.setFileType(FTP.BINARY_FILE_TYPE);
FileInputStream in = new FileInputStream(URL);
result = f.storeFile(newfile, in);
in.close();
f.logout();
f.disconnect();
}
It upload fine but not in particular path i also try as ftp://ftp.drivehq.com/myfolder
but it gives error in android unknown host exception like I need to upload file in particular folder So thanks in advance help me
Upvotes: 1
Views: 887
Reputation: 4638
Hi Please use the following code. it worked for me i have checked it.
SimpleFTP ftp = new SimpleFTP();
try
{
// Connect to an FTP server on port 21.
ftp.connect("host", 21, "username", "password");
// Set binary mode.
ftp.bin();
// Change to a new working directory on the FTP server.
ftp.cwd("/httpdocs/yourdestinationfolderinftp");
// Upload some files.
ftp.stor(new File("/mnt/sdcard/ftp.jpg"));
// Quit from the FTP server.
ftp.disconnect();
}
catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
Upvotes: 1