在 Android 上使用 FTP 上传图像 [英] Uploading images with FTP on Android

查看:25
本文介绍了在 Android 上使用 FTP 上传图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Android 上使用 FTP 上传图片?

How can I upload images using FTP on Android?

推荐答案

使用 SimpleFTP,只需将 simpleftp.jar 添加到您的类路径中,然后将包导入任何将使用它的类中:在这里下载

Use SimpleFTP, simply add simpleftp.jar to your classpath and import the package in whichever classes will use it: Download here

import org.jibble.simpleftp.*;

上传图片等时请确保使用二进制模式,否则可能会损坏.

Make sure you use binary mode when uploading images and suchlike, or they may become corrupted.

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();
}

这是所有功能,所以它不允许您下载文件!

This was all the functionality, so it does not let you download files!

这篇关于在 Android 上使用 FTP 上传图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆