apache-commons-net

How to copy a file on the FTP server to a directory on the same server in Java?

谁都会走 提交于 2019-11-27 20:13:58
I'm using Apache Commons FTP to upload a file. Before uploading I want to check if the file already exists on the server and make a backup from it to a backup directory on the same server. Does anyone know how to copy a file from a FTP server to a backup directory on the same server? public static void uploadWithCommonsFTP(File fileToBeUpload){ FTPClient f = new FTPClient(); FTPFile backupDirectory; try { f.connect(server.getServer()); f.login(server.getUsername(), server.getPassword()); FTPFile[] directories = f.listDirectories(); FTPFile[] files = f.listFiles(); for(FTPFile file:directories)

How to copy a file in FTP server using FTPClient in Java?

廉价感情. 提交于 2019-11-27 07:26:44
问题 I have a CSV file, and I need to copy it and rename it in the same path . I tried this after the FTP login: InputStream inputStream = ftpClient.retrieveFileStream(cvs_name +".csv"); ftpClient.storeFile(cvs_name2 + ".csv",inputStream); But when I verify the file on the server, it's empty. How can I copy a file and rename it? 回答1: I believe your code cannot work. You cannot download and upload a file over a single FTP connection at the same time. You have two options: Download the file

FTPClient corrupts the images while uploading to ftp server on android?

一曲冷凌霜 提交于 2019-11-27 07:01:33
问题 I'm trying to upload images to a FTP server (on my local PC) from Android Phone (HTC Desire HD). Images are going to FTP server but they are corrupted. And the method (ftpClient.storeFile()) throws IOException (Bad File Number) Please help me. This is the corrupted image link: http://imageshack.us/photo/my-images/820/komikb.jpg/ And this is the code: FTPClient ftpClient = new FTPClient(); try { ftpClient.connect("192.168.2.14"); ftpClient.setFileType(FTP.BINARY_FILE_TYPE); ftpClient

Make FTP server return files listed by timestamp with Apache FTPClient

限于喜欢 提交于 2019-11-27 06:29:08
问题 I have written this below code to connect to a remote FTP Server (vsftp in CentOS 6). (For brevity Exception handling is not shown here) FTPClient ftpClient = new FTPClient(); ftpClient.setConnectTimeout(20000); ftpClient.connect(serverip); ftpClient.enterLocalPassiveMode(); ftpClient.login(username, password); if (!FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) { ftpClient.disconnect(); throw new FTPConnectionClosedException("Unable to connect to FTP server..."); } FTPFile[]

Checking file existence on FTP server

旧街凉风 提交于 2019-11-27 04:50:24
Is there an efficient way to check the existence of a file on a FTP server? I'm using Apache Commons Net. I know that I can use the listNames method of FTPClient to get all the files in a specific directory and then I can go over this list to check if a given file exists, but I don't think it's efficient especially when the server contains a lot of files. listFiles(String pathName) should work just fine for a single file. Using a full path to a file in listFiles (or mlistDir ) call, as the accepted answer shows, should indeed work: String remotePath = "/remote/path/file.txt"; FTPFile[]

FTPClient - Java, upload file

…衆ロ難τιáo~ 提交于 2019-11-27 01:33:25
问题 I'm trying to do a VERY simple file upload. I want a Java FTPClient that can upload any file I tell it to. But the pdf always gets all messed up and my pdf editor (Adobe) won't open it, saying there is an I/O error. I'm using the following class: 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

How to copy a file on the FTP server to a directory on the same server in Java?

偶尔善良 提交于 2019-11-26 20:18:05
问题 I'm using Apache Commons FTP to upload a file. Before uploading I want to check if the file already exists on the server and make a backup from it to a backup directory on the same server. Does anyone know how to copy a file from a FTP server to a backup directory on the same server? public static void uploadWithCommonsFTP(File fileToBeUpload){ FTPClient f = new FTPClient(); FTPFile backupDirectory; try { f.connect(server.getServer()); f.login(server.getUsername(), server.getPassword());

Enable logging in Apache Commons Net for FTP protocol

牧云@^-^@ 提交于 2019-11-26 17:25:27
问题 Apache Commons Net library does not seem to send anything to any "logger". Can I somehow obtain a log file from an (FTP) session, for debugging purposes? For example raw FTP commands and responses from the server, like this: 220 Welcome USER ******* 331 Password required for ... PASS ******* 230 Logged on TYPE I 200 Type set to I QUIT 221 Goodbye 回答1: All protocol implementations in Apache Commons Net, including FTPClient , derive from SocketClient, which has a method

How to connect to FTPS server with data connection using same TLS session?

烂漫一生 提交于 2019-11-26 14:39:48
Environment: I'm using Sun Java JDK 1.8.0_60 on 64-bit Windows 7, using Spring Integration 4.1.6 (which internally appears to use Apache Commons Net 3.3 for FTPS access). I'm attempting to integrate with our application an automatic download from our client's FTPS server. I've done so successfully with SFTP servers using Spring Integration without any trouble for other clients without issues, but this is the first time a client has required us to use FTPS, and getting it to connect has been very puzzling. While in my real application I'm configuring Spring Integration using XML beans, to try

Checking file existence on FTP server

时光毁灭记忆、已成空白 提交于 2019-11-26 14:24:40
问题 Is there an efficient way to check the existence of a file on a FTP server? I'm using Apache Commons Net. I know that I can use the listNames method of FTPClient to get all the files in a specific directory and then I can go over this list to check if a given file exists, but I don't think it's efficient especially when the server contains a lot of files. 回答1: listFiles(String pathName) should work just fine for a single file. 回答2: Using a full path to a file in listFiles (or mlistDir) call,