如何在Android上使用FTP上传图像?在Android上通过FTP上传图像
回答
使用SimpleFTP,只需添加simpleftp.jar到类路径,并导入哪个类将使用它的包:Download here
import org.jibble.simpleftp.*;
确保你上传图片和诸如此类时使用二进制模式,或者他们可能会成为损坏。
try
{
SimpleFTP ftp = new SimpleFTP();
// Connect to an FTP server on port 21.
ftp.connect("ftp.somewhere.net", 21, "username", "password");
// Set binary mode.
ftp.bin();
// Change to a new working directory on the FTP server.
ftp.cwd("web");
// Upload some files.
ftp.stor(new File("webcam.jpg"));
ftp.stor(new File("comicbot-latest.png"));
// You can also upload from an InputStream, e.g.
ftp.stor(new FileInputStream(new File("test.png")), "test.png");
ftp.stor(someSocket.getInputStream(), "blah.dat");
// Quit from the FTP server.
ftp.disconnect();
}
catch (IOException e)
{
e.printStackTrace();
}
这是所有的功能,所以它不会让你下载文件!
public void sendFileViaFTP() {
FTPClient ftpClient = null;
try {
ftpClient = new FTPClient();
ftpClient.connect(InetAddress.getByName("ftp.myserver.com"));
if (ftpClient.login("myftpusername", "myftppass")) {
ftpClient.enterLocalPassiveMode(); // important!
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
String Location = Environment.getExternalStorageDirectory()
.toString();
String data = Location + File.separator + "FileToSend.txt";
FileInputStream in = new FileInputStream(new File(data));
boolean result = ftpClient.storeFile("FileToSend.txt", in);
in.close();
if (result)
Log.v("upload result", "succeeded");
ftpClient.logout();
ftpClient.disconnect();
}
} catch (Exception e) {
Log.v("count", "error");
e.printStackTrace();
}
}
这将肯定工作。我做了很多次。
这可能有点晚,但使用此方法上传总是会返回错误代码550(拒绝访问)。有什么建议么??? – shreyas 2014-06-13 06:20:36
@shreyas你解决了你的问题吗? – 2015-04-08 08:30:00
链接中断:(:( – 2016-01-30 11:22:59
- 1. 通过ftp上传图像
- 2. 在android上的FTP图像上传
- 3. 上传图像通过Android应用程序FTP服务器
- 4. 通过浏览器上传FTP上传
- 5. Symfony 3通过FTP上传
- 6. 通过ftp上传文件
- 7. 例外通过FTP上传
- 8. 通过Android将图像上传到wordpress
- 9. FTP上传图像错误
- 10. android ftp上传
- 11. 上传图像通过AJAX
- 12. 上传图像通过simpleimage.php
- 13. 上传图像通过URL
- 14. 如何在android上使用ftp上传图像
- 15. 通过HTML表单将图像上传到FTP
- 16. 通过FTP在php上传文件
- 17. 使用FTP在Codeigniter上传图像
- 18. 在Android上通过FTP下载文件
- 19. FTP上传,并在Android
- 20. FTP上传图片
- 21. 使用PHP通过FTP上传文件
- 22. php通过ftp大量上传
- 23. 上传文件到通过FTP
- 24. 通过PHP上传FTP表格
- 25. FTP通过PHP上传和下载
- 26. 通过FTP上传时执行脚本
- 27. FTP上传文件通过SSL C#
- 28. Bash脚本通过FTP上传文件
- 29. 通过PHP FTP上传整个目录
- 30. 通过FTP上传文件片段
[你如何将图片上传到FTP应用程序中的FTP服务器?](http://stackoverflow.com/questions/6464456/how-do-you-upload-images-to-an-ftp -server-within-an-android-app) – 2011-11-23 18:00:10
尽管链接副本更新,但它在这个问题没有答案的地方有答案。 – 2011-11-23 18:00:41
你问你会如何在android中实现一个FTP客户端?或者你只是想连接到FTP服务器。市场上似乎有几个FTP应用程序,但如果有任何工作或没有,我不知道。 – Falmarri 2010-07-07 05:09:16