如何在java中给出FTP地址?
我已经编写了从 FTP 服务器下载文件的代码。因为我在本地有 FTP 服务器,并且我想像“ftp://localhost/alfresco”一样访问。这是露天的 FTP。
我有以下代码
public class FtpTransfer {
public static final void main(String[] args)
{
FTPClient ftp = new FTPClient();
FileOutputStream br = null;
try
{
ftp.connect("ftp://localhost/alfresco");
ftp.login("admin", "admin");
String file = "KPUB//Admin//TMM//Pickup//TMM_TO_ARTESIA_06152010220246.xml";
br = new FileOutputStream("file");
ftp.retrieveFile("/"+file, br);
System.out.println("Downloaded...");
}
catch(IOException exception) {
System.out.println("Error : "+exception);
}
}
}
发生以下异常。
Error : java.net.UnknownHostException: ftp://localhost/alfresco
请告诉我应该如何提供 FTP 主机地址?
I have written the code which downloads the file from FTP server. Since I have my FTP server locally and I want to access like "ftp://localhost/alfresco". It was alfresco's FTP.
I have the following Code
public class FtpTransfer {
public static final void main(String[] args)
{
FTPClient ftp = new FTPClient();
FileOutputStream br = null;
try
{
ftp.connect("ftp://localhost/alfresco");
ftp.login("admin", "admin");
String file = "KPUB//Admin//TMM//Pickup//TMM_TO_ARTESIA_06152010220246.xml";
br = new FileOutputStream("file");
ftp.retrieveFile("/"+file, br);
System.out.println("Downloaded...");
}
catch(IOException exception) {
System.out.println("Error : "+exception);
}
}
}
The following exception occurs.
Error : java.net.UnknownHostException: ftp://localhost/alfresco
Please let me know how should I give the FTP Host Address?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
另请参阅
Also See
下面是一个示例,演示了与服务器的连接、更改当前工作目录、列出目录中的文件以及将文件下载到某个指定的目录。
Here is an example demonstrating connection to a server, changing present working directory, listing files in a directory and downloading a file to some specified directory.
尝试从您的网址中删除协议(“ftp://”)。
请查看示例 。
Try remove protocol ("ftp://") from your url.
And please, look at the example.
FTPClient.connect()
方法采用服务器的名称,而不是 URL。尝试:此外,您可能需要将
alfresco
放在其他地方。如果它是文件路径的一部分,The
FTPClient.connect()
method takes the name of a server, not a URL. Try:Also, you may need to put
alfresco
somewhere else. If it's part of the file path,