1

FTPClient 経由で ftp サーバーにファイルを送信しようとしましたが、応答文字列を取得すると、次のように表示されます。

553 ファイルを開けません: そのようなファイルまたはディレクトリはありません。

コードは次のとおりです。

try 
{
    FTPClient client = new FTPClient();
    client.connect(hostname);
    client.login(username, password);

    client.setFileType(FTP.BINARY_FILE_TYPE);
    client.enterLocalPassiveMode();
    client.changeWorkingDirectory(workingDir);          
    File dir = new File(savePath + fileName);
    FileInputStream fIS = new FileInputStream(dir);

    for(File files : dir.listFiles())
    {
        boolean success = client.storeFile(files.getPath(), fIS);
        Toast.makeText(getBaseContext(), client.getReplyString(), Toast.LENGTH_LONG).show();
        Toast.makeText(getBaseContext(), files.getPath() + " Stored = " + success, Toast.LENGTH_LONG).show();
    }

    fIS.close();
    client.logout();
} 
catch (SocketException e) 
{
    Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_LONG).show();
} 
catch (IOException e) 
{
    Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}

私は答えを求めてインターネット全体を探してきましたが、何もうまくいきませんでした。

4

1 に答える 1

1

CoolBeans の助けを借りて問題を修正しました。

同様の問題を抱えている人にとって、解決策は

1.次を変更します。

client.storeFile(files.getPath(), fIS);

に:

client.storeFile(files.getName(), fIS);

FileInputStream を for ループに移動し、次のように変更します。

new FileInputStream(files);
于 2012-06-28T11:24:28.390 に答える