apache-commons-net

Apache Commons FTP storeFileStream returns null

早过忘川 提交于 2020-05-14 02:25:46
问题 I am trying to upload a file in android to an FTP server using the apache.commons.ftp library. Note: I am using storeFileStream so that I can track the progress of the upload. ftpClient.enterLocalPassiveMode(); ftpClient.setFileType(FTP.BINARY_FILE_TYPE); InputStream inputStream = new FileInputStream(localFile); OutputStream outputStream = ftpClient.storeFileStream(remoteFile); byte[] buffer = new byte[8192]; int bytesRead; logMessage("Starting to upload file"); while ((bytesRead =

Error “227 Entering Passive Mode”/“Connection refused” when downloading from local FTP server in Android emulator

喜你入骨 提交于 2020-02-15 06:12:49
问题 I am trying to download a file from my local FileZilla Server with Java FTPSClient running in Android emulator. I've written this helpercode to download one File: public boolean downloadSingleFile(FTPSClient ftpClient, String remoteFilePath, File downloadFile) { OutputStream outputStream; Log.i("t1", remoteFilePath + " - " + downloadFile.getAbsolutePath()); try { outputStream = new BufferedOutputStream(new FileOutputStream( downloadFile)); ftpClient.setFileType(FTP.BINARY_FILE_TYPE); boolean

Images downloaded from “some” servers with FTPClient are corrupted

大憨熊 提交于 2020-01-23 17:27:06
问题 I need to download .png files from a FTP server in Java. I have 3 different servers, each one contain a folder with exactly the same .png files. On server 1 : If I download my .png file of 4686 bytes stored on this server with FTPClient (apache.commons.net.ftp), I get a 4706 bytes .png file, and I can't open it. If I download it with Total Commander, I get a 4686 bytes .png file, and I can open it. On server 2 and 3 : With FTPClient and Total Commander, I get in both case a 4686 bytes file

Can't download files with Arabic name with Java FTP client

十年热恋 提交于 2020-01-21 09:37:36
问题 I have Java code that connects to an FTP server and downloads files. If the file name contains Arabic letters, then it always fails to download. But if it's English, it downloads successfully. This is my code. If the path is like this then it fails to download: String actualFileLocation = "/RelatedDocumentUploads\\...\\2017-S2\\تقرير الربع الرابع تقرير 2017 (006)senton(18-01-2017).pdf" ; But if it's like the following it works fine: String actualFileLocation = "/RelatedDocumentUploads\\...\

SFTP connection with FTPSClient is failing

二次信任 提交于 2020-01-11 08:00:30
问题 Below code I'm trying to connect SFTP host using FTPSClient . Instead of FTP client, I'm using FTPSClient to connect. But I'm facing issue to connect. public static void main(String[] args) throws SocketException, IOException { String host ="sftphost.com"; String user = "abc"; String pwd = "pwd" final FTPSClient ftp = new FTPSClient(); System.out.println("host:"+host); ftp.connect(host,22); int reply = ftp.getReplyCode(); ftp.login(user, pwd); } 回答1: FTPS is not SFTP. You cannot use Apache

How to preserve date modified when retrieving file using Apache FTPClient?

蓝咒 提交于 2020-01-11 05:59:28
问题 I am using org.apache.commons.net.ftp.FTPClient for retrieving files from a ftp server. It is crucial that I preserve the last modified timestamp on the file when its saved on my machine. Do anyone have a suggestion for how to solve this? 回答1: This is how I solved it: public boolean retrieveFile(String path, String filename, long lastModified) throws IOException { File localFile = new File(path + "/" + filename); OutputStream outputStream = new FileOutputStream(localFile); boolean success =

Is there a way to tell if the FTP server is active or passive in the Java web program?

被刻印的时光 ゝ 提交于 2020-01-10 04:34:42
问题 I'm using the Apache-Commons-Net library. I want to know if the FTP server is active-mode or passive-mode. Is there a method like that in the Apache-Commons-Net library? ( GetDataConnectionMode() is a method that tells you the connected mode after connecting in Java. I want to check Maud before) private FTPClient ftp; // the code I want if(active){ ftp.enterLocalActiveMode(); }else{ ftp.enterLocalPassiveMode(); } // Apply active mode or passive mode to the environment of the server for

commons-net FTPSClient error in Java code

末鹿安然 提交于 2020-01-04 21:34:32
问题 I am using commons-net package for the first time and using the code below to ftp a file from a FileZilla server over SSL. I am facing an error when I run the program. What is wrong in the code? import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintWriter; import org.apache.commons.net.PrintCommandListener; import org.apache.commons.net.ftp.FTP; import org.apache.commons.net.ftp.FTPReply; import org.apache.commons.net.ftp.FTPSClient; public class CommonsNetFTPSTest

How to set working directory on FTPusing FTPClient

我是研究僧i 提交于 2020-01-03 05:35:09
问题 I'm using java FTPClient for FTPconnection. This library has storeFile method for saving a file on FTP. I use it like this: FTPClient ftpClient = new FTPClient(); //code for connection and login ... ftpClient.storeFile("test.jpg", stream); //stream is an InputStream Now, I need to set working directory on FTP. For example I want to save my .jpg in the specific folder. Is ftpClient.storeFile("1/test.jpg", stream); correct? Or is there another solution? 回答1: I think you should call FTPClient

Duplicate remote file over FTP protocol in Java (cp -p to Linux using sendCommand)

為{幸葍}努か 提交于 2019-12-30 11:54:26
问题 I m using Apache FTPClient . I was a do a copy of file in a folder just like cp -p , but from Java. How can I do that using 'sendCommand' method or will it be possible any other way? The rename method moves the file but does not keep a backup copy. 回答1: There's no standard way to duplicate a remote file over FTP protocol. Some FTP servers support proprietary or non-standard extensions for this though. So if your are lucky that your server is ProFTPD with mod_copy module, you can use FTP