apache-commons-net

Transfer raw binary with apache commons-net FTPClient?

为君一笑 提交于 2019-11-29 05:27:02
UPDATE: Solved I was calling FTPClient.setFileType() before I logged in, causing the FTP server to use the default mode ( ASCII ) no matter what I set it to. The client, on the other hand, was behaving as though the file type had been properly set. BINARY mode is now working exactly as desired, transporting the file byte-for-byte in all cases. All I had to do was a little traffic sniffing in wireshark and then mimicing the FTP commands using netcat to see what was going on. Why didn't I think of that two days ago!? Thanks, everyone for your help! I have an xml file, utf-16 encoded, which I am

Uploading a file to a FTP server from android phone?

自作多情 提交于 2019-11-29 01:33:21
问题 Following is the code that's suppose to create a text document and upload it to my FTP server. For some reason it doesn't seem to work. I used to the libraries provided at http://lavalatwork.blogspot.tw/2010/09/using-apache-commons-ftp-library-in.html for communicating with the FTP server. try { final String testString = new String("Hello"); FileOutputStream fOut = openFileOutput("samplefile.txt", MODE_WORLD_READABLE); OutputStreamWriter osw = new OutputStreamWriter(fOut); osw.write

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

怎甘沉沦 提交于 2019-11-28 13:07:17
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? Martin Prikryl 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 completely first (to a temporary file or to a memory). The accepted answer to How to copy a file on

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

我的未来我决定 提交于 2019-11-28 12:17:57
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.setFileTransferMode(FTP.BINARY_FILE_TYPE); ftpClient.setSoTimeout(10000); ftpClient.enterLocalPassiveMode(); if

Make FTP server return files listed by timestamp with Apache FTPClient

旧街凉风 提交于 2019-11-28 11:44:31
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[] filesList = ftpClient.listFiles(); for (FTPFile tmpFile : filesList) { if (tmpFile.isDirectory()) continue; /

FTPClient - Java, upload file

做~自己de王妃 提交于 2019-11-28 06:50:26
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(filename); client.storeFile("temp.pdf", fis); fis.close(); client.logout(); } catch (IOException e) { e

How do I configure client authentication with generated certificate in apache-commons net

对着背影说爱祢 提交于 2019-11-28 02:07:53
问题 First off, I know there is a similar question here but it doesn't answer my doubts. I have a FTPS server (vsftpd) configured with SSL. I've generated the appropriate keys with: openssl req -x509 -nodes -days 1825 -newkey rsa:2048 \ -keyout private/vsftpd.key \ -out certs/vsftpd.crt And configured the respective conf file in the server. Now, in the Java client code with Apache commons net, I'm able to communicate with the server over SSL with something like this: import java.io

When using Java Apache FTPClient for FTP TLS getting “Remote host closed connection during handshake” [duplicate]

大城市里の小女人 提交于 2019-11-28 00:28:24
This question already has an answer here: How to connect to FTPS server with data connection using same TLS session? 3 answers I ran a Java (1.8) program on Windows 10 64x for FTP TLS (org.apache.commons.net.ftp): FTPSClient ftpClient = new FTPSClient(); System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2"); // LISTENER ftpClient.addProtocolCommandListener( new PrintCommandListener(new PrintWriter(System.out), true)); ftpClient.connect(server); ftpClient.login(user, pass); // Enter local passive mode ftpClient.enterLocalPassiveMode(); // useEpsvWithIPv4 ftpClient.setUseEPSVwithIPv4

Transfer raw binary with apache commons-net FTPClient?

混江龙づ霸主 提交于 2019-11-27 23:00:14
问题 UPDATE: Solved I was calling FTPClient.setFileType() before I logged in, causing the FTP server to use the default mode ( ASCII ) no matter what I set it to. The client, on the other hand, was behaving as though the file type had been properly set. BINARY mode is now working exactly as desired, transporting the file byte-for-byte in all cases. All I had to do was a little traffic sniffing in wireshark and then mimicing the FTP commands using netcat to see what was going on. Why didn't I think

FtpClient storeFile always return False

萝らか妹 提交于 2019-11-27 21:20:14
Please figure this out. The code runs properly without any 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