Tag: ftp client

FTPClient.listFiles无法正常工作

我试图列出ftp服务器中特定目录下的所有文件。 FTPFile[] subFiles = ftpClient.listFiles(“directory”); 虽然目录是有效的,但是在调用listFiles时代码卡住了,可能是原因。 ? 此外,我想提一下,访问相同FTP服务器的单独netbeans项目使用相同的代码正常工作,但是maven项目遇到了问题。 请帮忙。

org.apache.commons.net.ftp.FTPClient listFiles()的问题

org.apache.commons.net.ftp.FTPClient listFiles listFiles()方法适用于127.0.0.1上的Filezilla服务器,但在公共FTP服务器(如belnet.be)的根目录下返回null 。 在下面的链接上有一个相同的问题,但enterRemotePassiveMode()似乎没有帮助。 Apache Commons FTPClient.listFiles 这可能是列表解析的问题吗? 如果是这样,怎么能解决这个问题呢? 编辑:这是一个目录缓存转储: FileZilla目录缓存转储 转储1个缓存目录 Entry 1: Path: / Server: anonymous@ftp.belnet.be:21, type: 4096 Directory contains 7 items: lrw-r–r– ftp ftp D 28 2009-06-17 debian lrw-r–r– ftp ftp D 31 2009-06-17 debian-cd -rw-r–r– ftp ftp 0 2010-03-04 13:30 keepalive.txt drwxr-xr-x ftp ftp D 4096 2010-02-18 14:22 mirror lrw-r–r– […]

Apache Commons FTPClient.listFiles

我在我的一个应用程序中使用org.apache.commons.net.ftp.FTPClient来使用FTP服务器。 我能够connect , login , pwd和pwd 。 但是,当我尝试list文件时,它不会返回该目录中的文件列表,我知道确实存在文件。 我使用FTPFile[] listFiles() ,它返回一个FTPFile的空数组。 请在下面找到我尝试此操作的代码段: String hostname = properties.getProperty(“FTP_SERVER”); String user = properties.getProperty(“FTP_USER”); String passwd = properties.getProperty(“FTP_PASSWD”); FTPClient client = new FTPClient(); client.connect(hostname); client.login(user, passwd); String reply = client.getStatus(); System.out.println(reply); client.enterRemotePassiveMode(); client.changeWorkingDirectory(“/uploads”); FTPFile[] files = client.listFiles(); System.out.println(files.length); for (FTPFile file : files) { System.out.println(file.getName()); } String[] fileNames = […]

Apache Commons FTPClient挂起

我们使用以下Apache Commons Net FTP代码连接到FTP服务器,轮询某些目录以查找文件,如果找到文件,则将它们检索到本地计算机: try { logger.trace(“Attempting to connect to server…”); // Connect to server FTPClient ftpClient = new FTPClient(); ftpClient.setConnectTimeout(20000); ftpClient.connect(“my-server-host-name”); ftpClient.login(“myUser”, “myPswd”); ftpClient.changeWorkingDirectory(“/loadables/”); // Check for failed connection if(!FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) { ftpClient.disconnect(); throw new FTPConnectionClosedException(“Unable to connect to FTP server.”); } // Log success msg logger.trace(“…connection was successful.”); // Change to the loadables/ directory […]

从FTPClient.getModificationTime()解析日期字符串

我试图解析一个日期字符串,这是FTP服务器上文件的修改日期。 以下是代码。 String dateString = mFTPClient.getModificationTime(PDF_FILE_NAME_PS); SimpleDateFormat dateFormat = new SimpleDateFormat(“yyyyMMddHHmmss”); Date modificationDate = dateFormat.parse(dateString.substring(dateString.indexOf(” “))); Log.v(TAG, “inside downloadservice dateString=”+dateString); Log.v(TAG, “inside downloadservice modificationdate=”+modificationDate.toString()); 我在日志中得到了这个 05-27 10:04:20.870: V/DownloadService(751): inside downloadservice dateString=213 20130523130035 05-27 10:04:20.890: V/DownloadService(751): inside downloadservice modificationdate=Sat Jul 23 07:30:35 AEDT 203 有人可以帮我这个吗?

用于Java中文件传输的FTP客户端服务器模型

好吧,我正在尝试用Java实现ftp服务器和ftp客户端。 我试图从服务器接收文件。 以下是代码行。 我能够实现服务器和客户端之间的连接,但也无法将文件名发送到服务器。 那么有人可以指导我这种方法是否正确,或者如果没有,请建议适当的更改。 服务器的实现: import java.net.*; import java.io.*; class MyServer { ServerSocket ss; Socket clientsocket; BufferedReader fromclient; InputStreamReader isr; PrintWriter toclient; public MyServer() { String str = new String(“hello”); try { // Create ServerSocket object. ss = new ServerSocket(1244); System.out.println(“Server Started…”); while(true) { System.out.println(“Waiting for the request…”); // accept the client request. clientsocket […]

FTPClient – Java,上传文件

我正在尝试做一个非常简单的文件上传。 我想要一个可以上传我告诉它的任何文件的Java FTPClient。 但pdf总是搞砸了,我的pdf编辑器(Adobe)不会打开它,说有一个I / O错误。 我正在使用以下课程: import org.apache.commons.net.ftp.FTPClient; …. FTPClient client = new FTPClient(); FileInputStream fis = null; try { client.connect(“mydomain.com”); client.login(“user”, “password”); String filename = “myPDF.pdf”; fis = new FileInputStream(filename); client.storeFile(“temp.pdf”, fis); fis.close(); client.logout(); } catch (IOException e) { e.printStackTrace(); } 为什么这不起作用,我该如何解决?

使用Apache Commons FTPClient监控进度

我有一个简单的FTPClient类,从FTP服务器下载文件。 我还需要监控下载的进度,但我没有看到怎样的方式。 实际下载文件function是一个简单的function (your ftp client name).retrieveFile(arg1,arg2); 如何监控下载进度? 谢谢,Anon。

FtpClient storeFile总是返回False

请弄清楚这一点。 代码正常运行,没有任何exception。 FTPClient ftp = new FTPClient(); ftp.connect(server); if(!ftp.login(username, password)) { ftp.logout(); return false; } int reply = ftp.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { ftp.disconnect(); return false; } InputStream in = new FileInputStream(localfile); ftp.setFileType(ftp.BINARY_FILE_TYPE, ftp.BINARY_FILE_TYPE); ftp.setFileTransferMode(ftp.BINARY_FILE_TYPE); Store = ftp.storeFile(destinationfile, in); in.close(); ftp.logout(); ftp.disconnect(); } catch (Exception ex) { ex.printStackTrace(); return false; } return Store; Buttttttttt return语句始终返回false,并且文件未上载到服务器上。 有人请帮忙。 […]

使用org.apache.commons.net.ftp.FTPClient保护FTP

有没有办法用org.apache.commons.net.ftp.FTPClient实现安全的FTP? 如果没有,Java的其他选项有哪些?