【问题标题】:i have already connected the ftp server, how can i get this file path?我已经连接了 ftp 服务器,如何获取这个文件路径?
【发布时间】:2014-03-23 19:14:05
【问题描述】:
public void runftpConnect(){
    boolean status = false;
    // Replace your UID & PW here


    status = ftpclient.ftpConnect("192.168.0.109", "root", "s20041644", 21);
    File dir = /*Environment.getExternalStorageDirectory();*/
    if (status == true) {
        Log.d(TAG, "Connection Success");
        localPrintFilesList(dir, "LOCAL FILES");
        Log.d(TAG, "localPrintFilesList");
        //status = ftpclient.ftpUpload(TEMP_FILENAME, TEMP_FILENAME, "/", cntx);

    } else {
        //Toast.makeText(getApplicationContext(), "Connection failed", 2000).show();
        Log.d(TAG, "Connection failed");
    }
}

所以。虽然我可以连接ftp服务器,但是如何获取文件路径呢?

我试过了

`String mString = "ftp://192.168.0.109/";

File dir = new File(mString);`

但它没有用。有什么办法可以通过修改这个来获取ftp文件路径?

File dir = /*Environment.getExternalStorageDirectory();*/

【问题讨论】:

    标签: android ftp urlconnection


    【解决方案1】:

    替换这个:

    File dir = /*Environment.getExternalStorageDirectory();*/
    

    有了这个:

    FTPFile[] dirs = null;
    FTPFile[] files = null;
    try {
        dirs = client.listDirectories();
        files = client.listFiles();
    } catch (IOException e) {
        e.printStackTrace();
    }
    

    现在您可以在 foreach 中使用 FTPFile 来收集有关文件或目录的信息。或者您可以通过以下方式获取您连接的目录的路径:

    try{
        String path = ftpclient.printWorkingDirectory();
    } catch (IOException e) {
        e.printStackTRace();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-11
      • 1970-01-01
      • 2023-04-06
      • 1970-01-01
      • 1970-01-01
      • 2017-09-01
      • 1970-01-01
      • 2011-09-20
      相关资源
      最近更新 更多