English 中文(简体)
删除使用 Java的FTP服务器的档案
原标题:Delete file from a FTP server using Java

I am writing an application that involves multiple clients. One client uploads a file using FTP to a server, and then another client downloads the file and deletes it. I am using the FTP server kind of as a middleman to exchange information because I do not want the user to have to port forward. I have figured out how to upload a file, but I cannot figure out how to delete the file. The command for deleting a file using FTP is:

DELE <filename>

我尝试这样做,但没有成功。 这里是我尝试的法典:

public static void deleteFile(String name) throws IOException
{
    URL url = new URL("ftp://a1111111:[email protected]/public_html/misc/screenshots/picture.png;type=i");
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(url.openConnection().getOutputStream()));
    writer.write("DELE picture.png");
    writer.flush();
}

我感觉到,“带”;档案名称和编号;我提供的可能是错的,因为我没有把名录列入这条路。 然而,由于我明确讲述了URL档案的路面,我不敢肯定我本应进入的路边;档案名称和编号。

我已经在这个网站上读到与这个问题非常相似的其他问题,以及所有答复都表明要使用图书馆。 这就是说,这些图书馆大多是用纯 Java写的,因此,该图书馆的开发商必须拿出办法,在没有图书馆的情况下做些什么。 我也想这样做。 除了我自己所做的事情外,我不希望附上更多的档案。 因此,请不要告诉我使用图书馆——它不是我所期待的。

如果需要澄清,请问!

EDIT: 如果我使用该守则来接收答复:

    byte[] response = new byte[conn.getInputStream().available()];
    conn.getInputStream().read(response);
    System.out.println("Response: " + new String(response));

我的指挥刚刚回过来:

Response: DELE test1.png
最佳回答
问题回答

你们能否利用一些金融计划客户来开展行动?

页: 1 来自阿帕奇共同点网。 易于使用。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签