FTP transfers files without error, but the file is not successfully written

 Problems when using FTPClient

 

code show as below

public class LUX_FtpFile_mxJPO {
public void uploadFTPFile(Context context, String args[]){
FTPClient ftpClient = new FTPClient();
FileInputStream fis = null;
try{
ftpClient.connect("luxottica-redcarpet.ftp.upload.akamai.com");
ftpClient.login("luxottica-redcarpet", "MO7OSsY5");
File srcFile = new File("/tmp/00R000003__2600.jpg");
fis = new FileInputStream(srcFile);
ftpClient.changeWorkingDirectory("758608/TEST/TMK/0R/");
ftpClient.setBufferSize(1024);
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
ftpClient.storeFile("00R000003__2600.jpg", fis);

} catch (SocketException e) {
e.printStackTrace();
throw new RuntimeException("ftp client error", e);
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("ftp client error", e);
}finally{
IOUtils.closeQuietly(fis);
try{
ftpClient.disconnect();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("close ftp exception", e);
}
System.out.println("uploaded succesfully");Is not given, the purpose of following the path simply brush out file} }
}




The solution
was added the following code F

tpClient.enterLocalPassiveMode ();


This is the set transmission mode has four transmission modes FTPClient
ACTIVE_LOCAL_DATA_CONNECTION_MODE
ACTIVE_REMOTE_DATA_CONNECTION_MODE
PASSIVE_LOCAL_DATA_CONNECTION_MODE
PASSIVE_REMOTE_DATA_CONNECTION_MODE

above method is set to the mode
PASSIVE_LOCAL_DATA_CONNECTION_MODE
According to the official document FTPClient, you can summarize
the main differences between the four different modes mainly because FTP can be established between the server and the local as well as servers and server.
The default transfer mode
ACTIVE_LOCAL_DATA_CONNECTION_MODE , while in this mode, data is transmitted from the server to the local 
if you want a local to the server, then you need to set the mode
PASSIVE_LOCAL_DATA_CONNECTION_MODE
is the above code
tpClient.enterLocalPassiveMode (); 


a detailed explanation refer to the official documentation
http://commons.apache.org/proper/commons-net/apidocs/org/apache/commons/net/ftp/FTPClient.html#ACTIVE_LOCAL_DATA_CONNECTION_MODE


Guess you like

Origin www.cnblogs.com/daniel123/p/12142907.html