Linux upload is not the same as the upload on Windows, testing on Windows is not a problem, but put on the Linux server running, uploaded files in Chinese garbled. Solution:
Ftputil.java Red Marking Place
Package cn.zto.util;
Import Java.io.ByteArrayInputStream;
Import Java.io.File;
Import Java.io.FileInputStream;
Import Java.io.FileOutputStream;
Import java.io.IOException;
Import Java.io.InputStream;
Import java.net.SocketException;
Import Org.apache.log4j.Logger;
Import Cn.zto.log4j.Log4jConfigurator;
Import Cn.zto.pusher.HeNanPusher;
Import Sun.net.TelnetInputStream;
Import Sun.net.TelnetOutputStream;
Import sun.net.ftp.FtpClient;
Import org.apache.commons.net.ftp.*;
@SuppressWarnings ({"Restriction", "unused"})
public class Ftputil {
Private Logger log = Log4jconfigurator.getlogger (Ftputil.class);
private static String encoding = System.getproperty ("file.encoding");
/**
* Local file name
*/
Private String localfilename;
/**
* Remote file name
*/
Private String remotefilename;
/**
* FTP client
*/
Private ftpclient ftpclient;
/**
* Server Connection
*
* @param IP
* Server IP
* @param Port
* Server Port
* @param user
* User Name
* @param password
* Password
* @param path
* Server Path
*/
public boolean connect (string hostname, int port, string username,
String password) {
FtpClient = new FtpClient ();
try {
Ftpclient.connect (hostname, port);
Ftpclient.setcontrolencoding ("UTF-8");
if (Ftpreply.ispositivecompletion (Ftpclient.getreplycode ())) {
if (Ftpclient.login (username, password)) {
return true;
}
}
} catch (Exception e) {
E.printstacktrace ();
This.log.debug ("Connect error");
return false;
}
return true;
}
/**
* Upload Files
*/
public boolean upload (string remotefilename, string xml) {
This.remotefilename = Remotefilename;
try {
InputStream input = new Bytearrayinputstream (xml.getbytes ("Utf-8"));
Ftpclient.changeworkingdirectory (New String (remotefilename
. GetBytes (encoding), "iso-8859-1"));
Ftpclient.storefile (remotefilename, input);
return true;
} catch (IOException ex) {
This.log.debug ("not upload" + ex.getmessage ());
return false;
}
}
}
File Content Build Office:
private static String encoding = System.getproperty ("file.encoding");//Gets the current system encoding, Windows is different from Linux, so that processing encoding can be obtained automatically
.....
Upload to Ecsscus
String remotefilename = "\\EcssCus\\" + OrderNo + ". xml";
Upload to Ciq
String remotefilename1 = "\\Ciq\\" + OrderNo + ". xml";
Upload to Ecssorders
String remotefilename2 = "\\Ciq\\Orders\\" + OrderNo + ". xml";
try {
XML = new String (Xml.getbytes (), encoding);
XML1 = new String (Xml1.getbytes (), encoding);
XML2 = new String (Xml2.getbytes (), encoding);
This.log.debug (XML);
} catch (Unsupportedencodingexception e) {
E.printstacktrace ();
}
f Upload files to FTP server on Linux