试图让我的Andr​​oid应用程序放在我的FTP服务器上的文件 [英] Trying to make my android application put files on my ftp server

查看:130
本文介绍了试图让我的Andr​​oid应用程序放在我的FTP服务器上的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了很多时间试图让这个code的工作,并在其目前的状态几乎完全反映了code,我发现,在<一个href="http://stackoverflow.com/questions/3482583/apache-ftpclient-failing-to-download-larger-files">Apache FtpClient的不能下载较大的文件。我也使用Apache的公共网络。 由于某种原因,我的应用程序一直无法完成client.connect一步,甚至当我插上FTP服务器应该工作的其他IP地址。

I have spent a lot of time trying to make this code work, and in its current state it almost exactly mirrors the code I found at Apache FTPClient failing to download larger files. I am also using apache commons net. for some reason my application never gets past the client.connect step, even when i plug in other IP addresses of ftp servers that should work.

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.*;

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;



public class FtpClientService extends Activity {
    //static int fail;


 public FtpClientService(){  
 }


 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
        WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.ftp);
    FtpConnect();
}

public static void FtpConnect(){
  String userName="usrname";
  String passWord = "password";
  String ftpAddress = "127.0.0.1"; //this isnt the ip address I was using...
  String retrieveFromFTPFolder = "/Pictures/";
  String strLine;
  DataInputStream inputStream = null;
  BufferedReader bufferedReader = null;
  FTPClient client = null;
  FTPFile[] ftpFiles = null;
  int reply;

  try{

      client = new FTPClient();
   client.setListHiddenFiles(true);
   client.connect(ftpAddress); //this right here is where it fails
   client.login(userName, passWord);
   client.setFileType(FTP.BINARY_FILE_TYPE);
      if(!client.completePendingCommand()) {
          client.logout();
          client.disconnect();
          System.err.println("File transfer failed.");

      }

  } catch (Exception e) {
   if (client.isConnected()) {
    try {
     client.logout();  
     client.disconnect();  
    } 
    catch (IOException f) {}
   }
  }
  finally{
   if (client.isConnected()) {
    try {
     client.logout();
     client.disconnect();
    }
    catch (IOException f){}
   }
  }  
 }

 public static void main(String[] args) {
  FtpConnect();
 }

在此先感谢!

Thanks in advance!

推荐答案

请尝试使用这样的:

client.connect(InetAddress.getByAddress(ftpAddress,new byte[]{127,0,0,1}));

这篇关于试图让我的Andr​​oid应用程序放在我的FTP服务器上的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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