Tag: ftp client

FTP上传错误“553无法创建文件”

import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPReply; import org.apache.commons.net.ftp.FTPFile; import java.io.*; public class FTPUpload{ public static boolean uploadfile(String server,String username,String Password,String source_file_path,String dest_dir){ FTPClient ftp=new FTPClient(); try { int reply; ftp.connect(server); ftp.login(username, Password); System.out.println(“Connected to ” + server + “.”); System.out.print(ftp.getReplyString()); reply = ftp.getReplyCode(); if(!FTPReply.isPositiveCompletion(reply)) { ftp.disconnect(); System.err.println(“FTP server refused connection.”); return false; } System.out.println(“FTP server connected.”); InputStream […]

收到FTP响应421。 服务器关闭连接

我正在编写一个JAVA代码,使用Apache Commons Net FTPClient遍历FTP位置并在Excel文件中获取输出。 代码正确执行大约5分钟,但然后给出IOException: org.apache.commons.net.ftp.FTPConnectionClosedException: FTP response 421 received. Server closed connection. 我正在使用commons-net-3.0.1.jar。 我做了一些研发并尝试过: setDefaultTimeout(6000); setConnectTimeout(3000); setSoTimeout(3000); enterLocalPassiveMode(); 并发送NOOP ,但仍然得到相同的错误。 我想要做的就是遍历一个目录,如果找到文件,那么在excel中找到文件名和文件更新日期,如果找到了目录,那么进入内部直到再找到文件。 请帮忙询问是否需要其他信息。 我是JAVA的新手。

FTP连接超时421:解析器错误

这个问题已被编辑。 我试图列出FTP目录中的所有文件 – 虽然代码在正常的Netbeans项目中运行时工作正常,但在Maven项目中使用相同的代码时,会导致连接超时421 。 我怎么能摆脱这个? 码: FTPClient ftpClient = new FTPClient(); ftpClient.connect(host, 21); ftpClient.login(user, pass); ftpClient.enterLocalPassiveMode(); ftpClient.setFileType(FTP.BINARY_FILE_TYPE); FTPClientConfig conf = new FTPClientConfig(FTPClientConfig.SYST_UNIX); ftpClient.configure(conf); inputStream = FTPUtil.downloadSingleFile(ftpClient, filePath); ftpClient.list(); // It works ftpClient.listNames(“/”); // It works ftpClient.changeWorkingDirectory(“/”); // It works FTPFile[] files = ftpClient.listFiles(“/”);// It hangs and stops 421 connection timed out FileZilla日志是: – (000370)04-04-2013 […]

正确检查FTP服务器连接

我在程序开始时打开了与FTP服务器的连接。 在我在服务器上执行操作之前,我想检查连接是否已成功建立。 最简单的快速方式,如果连接消失,我将尝试再次连接。 我使用此代码执行此操作: private boolean checkConnection() { try { boolean success = ftpClient.login(user_name, password); if(success) return true; else return false; } } 但是,此方法在连接关闭时抛出NullPointerexception。 我可以检查与ftpClient.connect(server, port); 但这就像试图重新连接一样。 有什么方法可以检查连接?

如何使用java从ftp服务器删除文件?

如何使用java程序从ftp服务器删除文件? 我可以使用以下代码成功上传ftp文件: public static void main(String[] args) throws IOException { // TODO Auto-generated method stub String s = “ftp://username:password@ftpclient:21/text.txt;type=i”; URL u = new URL(s); URLConnection uc = u.openConnection(); BufferedOutputStream bos = new BufferedOutputStream(uc.getOutputStream()); bos.write(67); bos.close(); System.out.println(“Done”); } 但是如何从这个ftp服务器中删除文件? 任何帮助将不胜感激………提前谢谢

如何将ArrayList从AsyncTask返回到另一个类?

我想从服务器使用AsyncTask获取Ftp文件夹列表,并将文件夹名称ArrayList返回到主类并更新微调器适配器。 在主要类我有适配器旋转器 //the array i want to update in AsyncTask static ArrayList directoriesTeacher = new ArrayList(); //The adapter createfile_spinTeacher = (Spinner) findViewById(R.id.createfile_spinTeacher); final ArrayAdapter dataAdapterTeacher = new ArrayAdapter(this, android.R.layout.simple_spinner_item,directoriesTeacher); dataAdapterTeacher.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); createfile_spinTeacher.setAdapter(dataAdapterTeacher); 在AsyncTask中: package com.nedoGarazas.learnanylanguage; import java.util.ArrayList; import org.apache.commons.net.ftp.FTP; import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPFile; import org.apache.commons.net.ftp.FTPReply; import android.os.AsyncTask; import android.util.Log; public class FtpTeacher extends AsyncTask<ArrayList, Void, ArrayList> […]

Apache Camel端点写AS400 FTP文件:

我试图通过camel端点将文件写入AS400 FTP,如下所示 ftp://user@host:21/QSYS.LIB/XINFT.LIB?password=password&passiveMode=true ftp://user@host:21/QSYS.LIB/XINFT.LIB?password=password 但写操作失败,出现以下exception Cannot change directory to: QSYS.LIB. Code: 550. Processed by failure processor: FatalFallbackErrorHandler[Pipeline[[Channel[Wrap[com.privasia.edi.core.routing.exception.CustErrorHandler@2003b7bd] -> com.privasia.edi.core.routing.exception.CustErrorHandler@2003b7bd], Channel[Log(ypn-cusres-containerData-outbound)[Error in YPN CUSRES Container Schedular call.]]]]] org.apache.camel.component.file.GenericFileOperationFailedException: File operation failed: 550-Specified library does not exist or cannot be accessed. 550 Current library not changed. Cannot change directory to: QSYS.LIB. Code: 550 at org.apache.camel.component.file.remote.FtpOperations.doChangeDirectory(FtpOperations.java:705)[218:org.apache.camel.camel-ftp:2.10.7] at org.apache.camel.component.file.remote.FtpOperations.changeCurrentDirectory(FtpOperations.java:683)[218:org.apache.camel.camel-ftp:2.10.7] […]

将文件FTP到服务器,但结果以零字节大小到达

我想使用FTPClient将文件上传到数据库服务器。 它显示文件已成功传输,但文件为空(大小为0字节)。 下面是我用来构建的源代码。 谁能解决这个问题? package Examples; import org.apache.commons.net.ftp.*; import java.io.FileInputStream; import java.io.IOException; public class Main { public static void main(String[] args) { FTPClient client = new FTPClient(); FileInputStream fis = null; try { client.connect(“server”); client.login(“userid”, “password”); System.out.print(“Message : ” + client.getReplyString()); client.changeWorkingDirectory(“/loaddata”); System.out.println(“Working Directory” + client.printWorkingDirectory()); client.setDefaultPort(22); int f1 = client.getDefaultPort(); boolean f2 = client.setFileType(FTPClient.BINARY_FILE_TYPE); […]

一旦FTP在java中完成,就会创建0 kb文件

我正在尝试将文件FTP到远程计算机上。 以下是我的代码: – FTPClient ftpClient = new FTPClient(); ftpClient.connect(“home.abc.com”); ftpClient.login(“remote”, “guesst12”); int replyCode = ftpClient.getReplyCode(); ftpClient.changeWorkingDirectory(“share”)) ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE); InputStream input = new FileInputStream(new File(“H:/testFile.txt”)); OutputStream out = ftpClient.storeFileStream(“testFile.txt”); Util.copyStream(input, out); out.close(); input.close(); ftpClient.completePendingCommand() ftpClient.logout(); ftpClient.disconnect(); 当我执行这段代码时,代码执行没有任何问题,但在远程机器上,当我检查文件时,正在创建文件,但没有内容(OKB)文件。 我在代码中遗漏了什么。 [更新]:我尝试使用以下代码存储文件: – if(ftpClient.storeFile(“testCopy.txt”, input)) { System.out.println(“File Stored Successfully”); } System.out.println(ftpClient.getReplyString()); 现在收到的回复代码是: – 451 Failure writing to local file. 这意味着什么。 […]

如何保留使用Apache FTPClient检索文件时修改的日期?

我正在使用org.apache.commons.net.ftp.FTPClient从ftp服务器检索文件。 在文件保存在我的机器上时,保留文件的最后修改时间戳至关重要。 有没有人建议如何解决这个问题?